Home > Net >  The asynchronous delegate how to catch exceptions
The asynchronous delegate how to catch exceptions

Time:11-08

The HTML code is as follows, the main function and test function are catch exceptions not
 public delegate bool AsyncDelegate (int loop); 
The static void Main (string [] args)
{
Console. WriteLine (" Hello World!" );
Try
{
The Test ();
}
Catch Exception (err)
{

}
}

Public static void Test ()
{
(LongRun AsyncDelegate DLGT=new AsyncDelegate);

IAsyncResult ar=DLGT. The BeginInvoke (1000, null, null);

While (ar) IsCompleted==false)
{
Thread.sleep (100);
}
Try
{
Bool test=DLGT. EndInvoke (ar);
}
Catch
{
Console. WriteLine (" error ");
}
}


Public static bool LongRun (int loop)
{
For (int I=0; i {
For (int j=0; J & lt; Loop; J++)
{
There was an error throw new Exception (" long run ");
}
}
return true;
}

CodePudding user response:

If it is the c # 6.0 or above, in ansync directly with the try catch can

CodePudding user response:

I use the.net 4.0 framwork, have what good method

CodePudding user response:

reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
if it is a c # 6.0 or above, in ansync directly with try catch can
. I use the net framwork of 4.0, what is a good way

CodePudding user response:

Promoter threads, then the parent thread to infinite loop blocking, then the whole a lot of cumbersome syntax to sucks, this is from where learn programming?

Delete the redundant code, to write a sequence code, don't cause trouble,

CodePudding user response:

reference 4 floor interacting in a professional developer response:
promoter thread, then the parent thread to infinite loop blocking, then the whole a lot of cumbersome syntax to sucks, this is from where learn programming?

Delete the redundant code, to write a sequence code, don't make antinomy,

My actual scenario is multi-threaded call a reading the database function, reading the database function return value for the datatable, the example above, is my question in order to simplify, don't know this multi-threaded return value read from database scenario, what do you have any good idea can provide? I just contact is multi-threaded
  •  Tags:  
  • C#
  • Related