private object GetResult(int millisecondsTimeout, bool exitContext, WaitHandle cancelWaitHandle, out Exception e) { e = null; if (WorkItem.WorkItemState.Canceled == this.GetWorkItemState()) { throw new WorkItemCancelException("Work item canceled"); } if (this.IsCompleted) { e = this._exception; return(this._result); } if (cancelWaitHandle == null) { WaitHandle waitHandle = this.GetWaitHandle(); bool flag = !STPEventWaitHandle.WaitOne(waitHandle, millisecondsTimeout, exitContext); this.ReleaseWaitHandle(); if (flag) { throw new WorkItemTimeoutException("Work item timeout"); } } else { WaitHandle waitHandle2 = this.GetWaitHandle(); int num = STPEventWaitHandle.WaitAny(new WaitHandle[] { waitHandle2, cancelWaitHandle }); this.ReleaseWaitHandle(); switch (num) { case -1: case 1: throw new WorkItemTimeoutException("Work item timeout"); } } if (WorkItem.WorkItemState.Canceled == this.GetWorkItemState()) { throw new WorkItemCancelException("Work item canceled"); } e = this._exception; return(this._result); }
public override bool WaitForIdle(int millisecondsTimeout) { SmartThreadPool.ValidateWorkItemsGroupWaitForIdle(this); return(STPEventWaitHandle.WaitOne(this._isIdleWaitHandle, millisecondsTimeout, false)); }