C#中async/await关键字的作用
作者:互联网
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);
}
标签:异步,Console,C#,await,mission,int,static,WriteLine,async 来源: https://blog.csdn.net/Brucexiaocai/article/details/114253363