我添加了AsyncCtpLibrary v.3。从异步网页抓取了一些示例代码。将它包装在TestFixture中以供玩耍。异步等待关键字错误
我收到错误:任何想法为什么?
错误1 - 无效的标记 '无效' 类,结构或接口成员声明
错误2 - ;预计
代码:
[TestFixture]
public class AsyncTests
{
[Test]
public async void AsyncRunCpu()
{
Console.WriteLine("On the UI thread.");
int result = await TaskEx.Run(
() =>
{
Console.WriteLine("Starting CPU-intensive work on background thread...");
int work = DoCpuIntensiveWork();
Console.WriteLine("Done with CPU-intensive work!");
return work;
});
Console.WriteLine("Back on the UI thread. Result is {0}.", result);
}
public int DoCpuIntensiveWork()
{
// Simulate some CPU-bound work on the background thread:
Thread.Sleep(5000);
return 123;
}
}
我假设你的意思是你使用VS11作为异步/等待关键字。不知道它是否会有很大的不同,但尝试新的Task.Factory.StartNew。在运行命令之后尝试添加.Result。 .Result是任务返回类型,在本例中为int – Jon 2012-03-02 20:33:19
检查“My Documents”下是否有Async CTP文件夹。异步CTP [在论坛上讨论](http://social.msdn.microsoft.com/Forums/en-US/async/threads)有许多安装问题。归结起来,异步CTP是一种带外更新,会干扰其他VS更新。在这一点上(VS11迫在眉睫),我认为他们不太可能修复安装程序。一旦VS11发布,我预计Async CTP将被拉出并且不再可用。 – 2012-03-03 00:44:24