Created
December 6, 2011 08:31
FeedReader: ふたつめのテスト ~ Wait() を書かないとどうなる?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void ReadAsyncTest2_補足_Waitは無くてもOK() | |
{ | |
Stopwatch sw = Stopwatch.StartNew(); | |
Task<FeedData> task = (new FeedReader()).ReadAsync(RssUrl); | |
sw.Stop(); | |
Assert.IsTrue(200L > sw.ElapsedMilliseconds); //実際には 50mSec 程度 | |
Assert.IsFalse(task.IsCompleted, "ReadAsync 呼び出し直後"); //非同期実行中 | |
sw.Restart(); | |
//task.Wait(); // ← task.Wait()を書かなくても…!! | |
FeedData fd = task.Result; // ← 非同期実行中に結果の取出し!? エラーなんじゃ…? いいえ、ちゃんと結果が取れます! | |
sw.Stop(); | |
Assert.IsTrue(100L < sw.ElapsedMilliseconds); //実際には 500~1000mSec 程度掛かっている | |
Assert.IsTrue(task.IsCompleted, "task.Result を読みだしたところで Wait() されるっぽい"); //非同期実行は完了している! | |
StringAssert.StartsWith(fd.Title, "Amazon.co.jp: 本"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment