你好,我想了解任務和異步方法的概念。我一直在玩這段代碼有一段時間沒有用。有人能告訴我如何從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