1
다음과 같이 ActionBlock을 사용하여 테스트 할 작은 테스트 메소드가 있습니다. 예상되는 순서대로 추적 메시지를 기록하지만 완료되지는 않습니다. 시험 방법은 결코 종료되지 않습니다.ActionBlock 테스트 메소드가 완료되지 않음
내가 뭘 잘못하고 있니? 미리 Thx.
[TestMethod]
public async Task ActionBlockTest()
{
var rnd = new Random(DateTime.Now.Millisecond);
var delay = new ActionBlock<int>(item =>
{
var start = DateTime.Now;
Trace.WriteLine(string.Format("{0:ss fff} item start processing ({1})", start, item));
return Task.Delay(item).ContinueWith(t => Trace.WriteLine(string.Format("{0:ss fff} item finished processing ({1}) took {2} ms", DateTime.Now, item, (DateTime.Now - start).TotalMilliseconds)));
}, new ExecutionDataflowBlockOptions
{
BoundedCapacity = 4,
MaxDegreeOfParallelism = 2
});
for(int i = 0; i < 8; i++)
{
var d = rnd.Next(100, 1000);
Trace.WriteLine(string.Format("{0:ss fff} posting {1}", DateTime.Now, d));
await delay.SendAsync(d);
}
await delay.Completion;
}
멋진 캐치, 고맙습니다. :) –