110,532
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ParallelForeach1
{
delegate long MyDel(int first,int second);
class Program
{
static long Sum(int x, int y)
{
Console.WriteLine(" Inside Sum");
Thread.Sleep(100);
return x + y;
}
static void Main()
{
MyDel del = new MyDel(Sum);
IAsyncResult iar = del.BeginInvoke(3, 5, null, null);
Console.WriteLine("After BeginInvoke");
while (!iar.IsCompleted)
{
Console.WriteLine("Not Done");
Console.WriteLine("Hello World");
}
Console.WriteLine("Done");
long result = del.EndInvoke(iar);
Console.WriteLine("Result: {0}", result);
Console.Read();
}
}
}
while (!iar.IsCompleted)
{
Thread.Sleep(10);
Console.WriteLine("Not Done");
Console.WriteLine("Hello World");
}