Beispiel #1
0
 /// <summary>
 /// Try to de-queue from the Channel with a timeout period.
 /// </summary>
 /// <returns>
 /// Returns Boolean, representing whether or not data was de-queued from the Channel.
 /// </returns>
 /// <param name="milliseconds">
 /// Specifies the timeout period for de-queueing.
 /// </param>
 /// <param name="result">
 /// Data that was de-queued from the Channel.
 /// </param>
 /// <exception cref="System.Threading.ThreadInterruptedException">
 /// Thrown when de-queueing is interrupted.
 /// </exception>
 public virtual bool TryDequeue(int milliseconds, out T result)
 {
     // Catch cases which mean infinite timeout period
     if (milliseconds < -1)
     {
         milliseconds = -1;
     }
     // Can de-queue happen
     if (_access.TryAcquire(milliseconds))
     {
         try
         {
             result = _queue.Dequeue();
             return(true);
         }
         catch (ThreadInterruptedException)
         {
             // Catch the exception if it is thrown and force release then throw
             _access.ForceRelease();
             throw;
         }
     }
     // Otherwise, assign the out variable the value of the default type, T, and return false
     else
     {
         result = default(T);
         return(false);
     }
 }
        /// <summary>
        /// De-queue from the BoundedChannel.
        /// </summary>
        /// <returns>
        /// Returns data de-queued from the BoundedChannel.
        /// </returns>
        /// <exception cref="System.Threading.ThreadInterruptedException">
        /// Thrown when de-queueing is interrupted.
        /// </exception>
        public override T Dequeue()
        {
            // Assign the value returned from the call to base.Enqueue
            T data = base.Dequeue();

            // To avoid being interrupted while releasing, use ForceRelease
            _upperBoundary.ForceRelease();
            // Return the de-queued value
            return(data);
        }