static void Main(string[] args)
{
//AsnycRes_Dog dog = new AsnycRes_Dog();
//var man = new Man(dog);
//var thief = new Thief(dog);
//dog.HappenEvent();
//Console.ReadKey();
//异步阻塞 通过endinvoke
BeginInvoeUserTest be = new BeginInvoeUserTest();
Program p = new Program();
be.mutiDel = be.WaysToMuti;
var Ways = be.mutiDel;
IAsyncResult Result = Ways.BeginInvoke(10, 20, p.CWWAYS, null);
while (!Result.IsCompleted)
{
Console.WriteLine("Runing .........");
Thread.Sleep(500);
}
int Res = Ways.EndInvoke(Result);
Console.WriteLine(Res);
Console.ReadKey();
}
public void CWWAYS(IAsyncResult ir)
{
Console.WriteLine("计算完成了!!!");
}
class BeginInvoeUserTest
{
public delegate int MutiNum(int a, int b);
public MutiNum mutiDel;
public int WaysToMuti(int a, int b)
{
int Result = a+b;
for (int i = 0; i < 10; i++)
{
Thread.Sleep(500);
Result += a;
}
return Result;
}
}
beginInvke带回调函数使用
最新推荐文章于 2023-09-23 13:32:58 发布