public void WaitAny() { STP smartThreadPool = new STP(); IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue); bool success = false; IWorkItemResult[] wirs = new IWorkItemResult[5]; for (int i = 0; i < wirs.Length; ++i) { wirs[i] = workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null); } int index = STP.WaitAny(wirs); if (wirs[index].IsCompleted) { int result = (int)wirs[index].GetResult(); if (1 == result) { success = true; } } smartThreadPool.Shutdown(); Assert.IsTrue(success); }
public void WaitAnyWithTimeoutFailure() { STP smartThreadPool = new STP(); IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue); IWorkItemResult[] wirs = new IWorkItemResult[5]; for (int i = 0; i < wirs.Length; ++i) { wirs[i] = workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null); } int index = STP.WaitAny(wirs, 10, true); bool success = (index == WaitHandle.WaitTimeout); smartThreadPool.Shutdown(); Assert.IsTrue(success); }