이 이미 그래서 당신은 바퀴를 재발견하려고하지 않습니다 있는지 확인 Task.WaitAll (작업 [], CancellationToken) 방법 .NET 4에서 제공되는 시도 할 수 있습니다.
어떤 이유로 든 .NET 4로 이동할 수 없거나 Task 클래스를 사용하지 않는 기존 코드에 너무 커밋 된 경우 Task.WaitAll()이 수행하는 것과 비슷한 것을 구현할 수 있습니다. 기본 구성표는 WaitHandles 목록을 아래로 내려가 WaitAny()를 사용하여 차례로 하나씩 기다리면 중단 요청을 볼 수도 있습니다. 이와 같이 :
/// <summary>
/// Wait for all events with option to abort the wait
/// </summary>
/// <param name="waitHandles">Synchronization objects to wait for</param>
/// <param name="abortEvent">Event that signals an abort</param>
/// <returns>false if the wait was aborted</returns>
public static bool WaitAll(WaitHandle[] waitHandles, WaitHandle abortEvent) {
WaitHandle[] pair = new WaitHandle[] { abortEvent, null };
for (int ix = 0; ix < waitHandles.Length; ++ix) {
pair[1] = waitHandles[ix];
if (WaitHandle.WaitAny(pair) == 0) return false;
}
return true;
}
한스 감사합니다. 정확히 알고 싶습니다 .--). 바울의 최선의 소원 – Stochastically