WaiterEntry.Signal C# (CSharp) Метод

Signal() публичный Метод

Signal the waiter that it got a work item.
public Signal ( WorkItem workItem ) : bool
workItem WorkItem
Результат bool
            public bool Signal(WorkItem workItem)
            {
                lock(this)
                {
                    if (!_isTimedout)
                    {
                        _workItem = workItem;
                        _isSignaled = true;
                        _waitHandle.Set();
                        return true;
                    }
                }
                return false;
            }

Usage Example

        /// <summary>
        /// Enqueue a work item to the queue.
        /// </summary>
        public bool EnqueueWorkItem(WorkItem workItem)
        {
            // A work item cannot be null, since null is used in the
            // WaitForWorkItem() method to indicate timeout or cancel
            if (null == workItem)
            {
                throw new ArgumentNullException("workItem", "workItem cannot be null");
            }

            bool enqueue = true;

            // First check if there is a waiter waiting for work item. During
            // the check, timed out waiters are ignored. If there is no
            // waiter then the work item is queued.
            lock (this)
            {
                ValidateNotDisposed();

                if (!_isWorkItemsQueueActive)
                {
                    return(false);
                }

                while (_waitersCount > 0)
                {
                    // Dequeue a waiter.
                    WaiterEntry waiterEntry = PopWaiter();

                    // Signal the waiter. On success break the loop
                    if (waiterEntry.Signal(workItem))
                    {
                        enqueue = false;
                        break;
                    }
                }

                if (enqueue)
                {
                    // Enqueue the work item
                    _workItems.Enqueue(workItem);
                }
            }
            return(true);
        }