Task.Factory.StartNew(async () =>
{
using (dagCallBack["tcsyfpifpmatch"])
{
LogHtml.WriteHtmlInfo(LogType.LogInfo, "【返回】" + JsonConvert.SerializeObject(response), Color.Black);
await dagCallBack["tcsyfpifpmatch"].ExecuteAsync(response);
}
}
);
async和await的异步
static void Main(string[] args)
{
ShowNameAsync();
Console.WriteLine("等待名字或者干点其他的事情。");
Thread.Sleep(1000);
Console.WriteLine("名字还没起好?");
}
static async Task ShowNameAsync()
{
string name = await Task.Run(() => { Console.WriteLine("开始起名字"); Thread.Sleep(3000); Console.WriteLine("名字起好了"); return "名字:李磊"; });
Console.WriteLine(name);
return;
}
结果: