Amib.Threading.Internal.STPEventWaitHandle.WaitOne C# (CSharp) Метод

WaitOne() статический приватный Метод

static private WaitOne ( WaitHandle waitHandle, int millisecondsTimeout, bool exitContext ) : bool
waitHandle System.Threading.WaitHandle
millisecondsTimeout int
exitContext bool
Результат bool
        internal static bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout, bool exitContext)
        {
            return waitHandle.WaitOne(millisecondsTimeout);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Get the result of the work item.
        /// If the work item didn't run yet then the caller waits for the result, timeout, or cancel.
        /// In case of error the e argument is filled with the exception
        /// </summary>
        /// <returns>The result of the work item</returns>
        private object GetResult(
            int millisecondsTimeout,
            bool exitContext,
            WaitHandle cancelWaitHandle,
            out Exception e)
        {
            e = null;

            // Check for cancel
            if (WorkItemState.Canceled == GetWorkItemState())
            {
                throw new WorkItemCancelException("Work item canceled");
            }

            // Check for completion
            if (IsCompleted)
            {
                e = _exception;
                return(_result);
            }

            // If no cancelWaitHandle is provided
            if (null == cancelWaitHandle)
            {
                WaitHandle wh = GetWaitHandle();

                bool timeout = !STPEventWaitHandle.WaitOne(wh, millisecondsTimeout, exitContext);

                ReleaseWaitHandle();

                if (timeout)
                {
                    throw new WorkItemTimeoutException("Work item timeout");
                }
            }
            else
            {
                WaitHandle wh     = GetWaitHandle();
                int        result = STPEventWaitHandle.WaitAny(new WaitHandle[] { wh, cancelWaitHandle });
                ReleaseWaitHandle();

                switch (result)
                {
                case 0:
                    // The work item signaled
                    // Note that the signal could be also as a result of canceling the
                    // work item (not the get result)
                    break;

                case 1:
                case STPEventWaitHandle.WaitTimeout:
                    throw new WorkItemTimeoutException("Work item timeout");

                default:
                    Debug.Assert(false);
                    break;
                }
            }

            // Check for cancel
            if (WorkItemState.Canceled == GetWorkItemState())
            {
                throw new WorkItemCancelException("Work item canceled");
            }

            Debug.Assert(IsCompleted);

            e = _exception;

            // Return the result
            return(_result);
        }
All Usage Examples Of Amib.Threading.Internal.STPEventWaitHandle::WaitOne