static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
addMethod = new AddDelegate(Add);
addMethod.BeginInvoke(0, 1, new AsyncCallback(CompleteMethod), "主线程");
}
//声明委托
public delegate int AddDelegate(int a, int b);
public static AddDelegate addMethod;
//函数
public static int Add(int a, int b)
{
Thread.Sleep(5000);
return a + b;
}
private static void CompleteMethod(IAsyncResult async)
{
if (async.IsCompleted)
{
int d = addMethod.EndInvoke(async);
}
}
}
异步调用函数
最新推荐文章于 2024-12-13 15:06:08 发布