using System;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static void Main()
{
test();
}
public async static void test(){
var result = await Task<string>.Factory.StartNew(() =>
{
Thread.Sleep(1000);
return "Результат обработки";
});
Console.WriteLine(result);
}
}
因为程序在任务休眠时有时间完成。
后台任务不会延长程序的运行时间。