static void Main(string[] args)
{
int i = 1;
while (true)
{
doWork2(i);
Thread.Sleep(1000);
i++;
}
}
/// <summary>
/// async/await 语法用看起来像写同步代码的方式来优雅地处理异步操作
/// </summary>
/// <param name="mission"></param>
static async void doWork(int mission)
{
await Task.Run(()=> {
Console.WriteLine("异步开始=====>"+mission);
Thread.Sleep(3000);
Console.WriteLine("异步结束=====>"+mission);
});
Console.WriteLine("观察者====>" + mission);
}
static void doWork2(int mission)
{
Task.Run(() => {
Console.WriteLine("异步开始=====>" + mission);
Thread.Sleep(3000);
Console.WriteLine("异步结束=====>" + mission);
});
Console.WriteLine("观察者====>" + mission);
}