AsyncCtpLibrary v.3 を追加しました。非同期 Web ページからサンプル コードを取得しました。それを 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;
}
}