110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var method = new Func<int, int, int>(Times);
Console.WriteLine("程序开始");
method.BeginInvoke(3, 5, PrintResult, method);
Console.WriteLine("请按任意键退出程序.......");
Console.ReadKey();
}
static int Times(int x, int y)
{
Thread.Sleep(5000);
return x * y;
}
static void PrintResult(IAsyncResult h)
{
var m = (Func<int, int, int>)h.AsyncState;
Console.WriteLine("结果是{0}。", m.EndInvoke(h));
}
}
}
using System;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var method= new Func<int,int,int>(Times);
Console.WriteLine("程序开始");
method.BeginInvoke(3, 5, h =>
{
Console.WriteLine("结果是{0}。", method.EndInvoke(h));
}, null);
Console.WriteLine("请按任意键退出程序.......");
Console.ReadKey();
}
static int Times(int x, int y)
{
Thread.Sleep(5000);
return x * y;
}
}
}