は、私はこれは私のテストで呼び出されたスリープ非同期CTP v3では、MSテストとのThread.sleep
public Task LongRunning() {
return Task.Factory.StartNew(
() => {
Trace.TraceInformation("Start Sleep");
Thread.Sleep(10000);
Trace.TraceInformation("End Sleep");
});
}
を使用して、長い実行中のタスクの方法を持っており、それが正常に
[TestMethod]
public void SimpleContinueWith() {
Trace.TraceInformation("Start");
LongRunning()
.ContinueWith(
t => Trace.TraceInformation("End")
).Wait();
}
> QTAgent32.exe Information: 0 : Start
> QTAgent32.exe Information: 0 : Start Sleep
> QTAgent32.exe Information: 0 : End Sleep
> QTAgent32.exe Information: 0 : End
しかし、使用して動作します非同期/テストがまっすぐ落ちるのを待つ
[TestMethod]
public async void SimpleAwait() {
Trace.TraceInformation("Start");
await LongRunning();
Trace.TraceInformation("End");
}
> QTAgent32.exe Information: 0 : Start
> QTAgent32.exe Information: 0 : Start Sleep
それはなぜですか?
スーパー、おかげで、nugetパッケージをインストールしhttp://nuget.org/List/Packages/Nito.AsyncEx –
はところで、私がテストを書いていた理由でしたParallel.ForEachを呼び出す非同期メソッドと再帰 - async/awaitでは動作しませんが、上のテストと同じように動作します。すなわち、呼び出され、戻ってくることはありません。 AsyncContextがこれを修正しました - ありがとう –