我试图用异步 CTP 弄脏我的手,我注意到编译器抱怨异步返回类型。其他类型有什么问题?
一个简单的演示
static void Main(string[] args)
{
DoWork();
Console.WriteLine("Returned to main");
Console.Read();
}
// why do I need to return void, Task or Task<T> here?
// I know I can use something like Task<IEnumerable<string>>
private static async string[] DoWork()
{
Console.WriteLine("DoWork started");
return await Task.Factory.StartNew(
delegate
{
Thread.Sleep(2000);
Console.WriteLine("DoWork done");
return new List<string>();
});
}