2017년 6월 29일 목요일

[C#] Task.WhenAll , WhenAny

Task.WhenAll(task1 , task2 )를 풀어서 쓰면 다음과 같다.

var exceptions = new List();
try{ task1.Wait() ;} catch ( AggregateException ex) { exceptions.Add(ex) ;}
try{ task2.Wait() ;} catch ( AggregateException ex) { exceptions.Add(ex) ;}
if(exceptions.Count > 0 ) throw new AggregateException (exceptions )

 따라서  WhenAll에 task1,task2를 넣기 전에 task1,task2는 미리 실행이 되어 있어야 한다.

댓글 없음:

댓글 쓰기