【发布时间】:2009-09-23 09:27:07
【问题描述】:
由于我可以使用委托执行异步操作,我怀疑在我的应用程序中使用 System.Threading 的机会很小。是否有任何我无法避免 System.Threading 的重要情况?
(只是我在学习阶段)。
例子:
class Program
{
public delegate int Total (int a,int b);
static void Main()
{
Total tl = new Total(SumUp);
IAsyncResult isany=tl.BeginInvoke(20,20, null, null);
while (!isany.IsCompleted)
{
Console.WriteLine("Busy with other work");
}
int ans = tl.EndInvoke(isany);
Console.WriteLine("Result ={0}", ans);
}
static int SumUp(int a,int b)
{
a = a * a;
b = b * b;
return a + b;
}
}
【问题讨论】:
标签: c# multithreading delegates