110,537
社区成员
发帖
与我相关
我的任务
分享
public delegate bool AsyncDelegate(int loop);
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
try
{
Test();
}
catch(Exception err)
{
}
}
public static void Test()
{
AsyncDelegate dlgt = new AsyncDelegate(LongRun);
IAsyncResult ar = dlgt.BeginInvoke(1000, null, null);
while (ar.IsCompleted == false)
{
Thread.Sleep(100);
}
try
{
bool test=dlgt.EndInvoke(ar);
}
catch
{
Console.WriteLine("发生错误");
}
}
public static bool LongRun(int loop)
{
for (int i = 0; i < loop; i++)
{
for (int j = 0; j < loop; j++)
{
throw new Exception("long run 发生错误");
}
}
return true;
}