我添加了 AsyncCtpLibrary v.3。从异步网页中获取了一些示例代码。把它包裹在一个 TestFixture 中来玩。
我收到错误:任何想法为什么?
错误 1 - 类、结构或接口成员声明中的标记“void”无效
错误 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;
}
}