你好,我想了解任务和异步方法的概念。我一直在玩这段代码有一段时间没有用。有人能告诉我如何从test()方法得到返回值并将该值赋给变量?如何获得异步方法的返回值?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Task test1 = Task.Factory.StartNew(() => test());
System.Console.WriteLine(test1);
Console.ReadLine();
}
public static async Task<int> test()
{
Task t = Task.Factory.StartNew(() => { Console.WriteLine("do stuff"); });
await t;
return 10;
}
}
}
看看我的[curah](http://curah.microsoft.com/45553/asyncawait-general“async-await General”)上的文章。 – 2014-09-01 10:43:02