Example #1
0
        /// <summary>
        ///   Raises the <see cref="WorkerException"/> event.
        /// </summary>
        /// <param name="e">
        ///   A <see cref="ResourceExceptionEventArgs"/> that contains the event data.
        /// </param>
        /// <remarks>
        ///   The <b>OnWorkerException</b> method allows derived classes to handle the <see cref="WorkerException"/>
        ///   event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
        ///   <para>
        ///   When a derived class calls the <b>OnWorkerException</b> method, it raises the <see cref="WorkerException"/> event by
        ///   invoking the event handler through a delegate. For more information, see
        ///   <a href="ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpguide/html/cpconProvidingEventFunctionality.htm">Raising an Event</a>.
        ///   </para>
        ///   <para>
        ///   The <b>WorkQueue</b> is <see cref="Pause">paused</see> and in an inconsistent state.
        ///   The <b>WorkQueue</b> should not be used again.
        ///   </para>
        /// </remarks>
        protected virtual void OnWorkerException(ResourceExceptionEventArgs e)
        {
            ResourceExceptionEventHandler handler;

            lock (eventLock)
            {
                handler = workerException;
            }
            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #2
0
        /// <summary>
        ///   Invoked by the <see cref="WorkerPool"/> when an exception is thrown outside of normal
        ///   processing.
        /// </summary>
        /// <param name="e">
        ///   A <see cref="ResourceExceptionEventArgs"/> that contains the event data.
        /// </param>
        /// <remarks>
        ///   <b>HandleResourceException</b> is called by the <see cref="WorkerPool"/> when
        ///   an exception is thrown outside of the <see cref="IWork.Perform">normal processing</see>
        ///   of a <see cref="IWorkItem"/>.
        ///   <para>
        ///   An exception at this point leaves the <see cref="WorkQueue"/> in an inconsistent state.  The
        ///   follow actions are performed:
        ///   <list type="bullet">
        ///   <item><description>The queue is <see cref="Pause">paused</see></description></item>
        ///   <item><description>The <see cref="WorkerException"/> event is raised.</description></item>
        ///   <item><description>All threads calling <see cref="WaitAll"/> will receive the exception.</description></item>
        ///   </list>
        ///   </para>
        /// </remarks>
        public void HandleResourceException(ResourceExceptionEventArgs e)
        {
            lock (completed)
            {
                Pause();
                internalException = e.Exception;

                // Tell the world.
                OnWorkerException(e);

                // Wakeup any threads in WaitAll and let them throw the exception.
                Monitor.PulseAll(completed);
            }
        }
Example #3
0
        /// <summary>
        ///   Raises the <see cref="ThreadException"/> event.
        /// </summary>
        /// <param name="e">
        ///   A <see cref="ResourceExceptionEventArgs"/> that contains the event data.
        /// </param>
        /// <remarks>
        ///   The <b>OnThreadException</b> method allows derived classes to handle the <see cref="ThreadException"/>
        ///   event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
        ///   <para>
        ///   When a derived class calls the <b>OnThreadException</b> method, it raises the <see cref="ThreadException"/> event by 
        ///   invoking the event handler through a delegate. For more information, see 
        ///   <a href="ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpguide/html/cpconProvidingEventFunctionality.htm">Raising an Event</a>.
        ///   </para>
        /// </remarks>
        protected virtual void OnThreadException(ResourceExceptionEventArgs e)
        {
            ResourceExceptionEventHandler handler;

             lock (eventLock)
             {
            handler = threadException;
             }
             if (handler != null)
            handler(this, e);
        }
Example #4
0
        /// <summary>
        ///   Invoked by the <see cref="WorkerPool"/> when an exception is thrown outside of normal
        ///   processing.
        /// </summary>
        /// <param name="e">
        ///   A <see cref="ResourceExceptionEventArgs"/> that contains the event data.
        /// </param>
        /// <remarks>
        ///   <b>HandleResourceException</b> is called by the <see cref="WorkerPool"/> when
        ///   an exception is thrown outside of the <see cref="IWork.Perform">normal processing</see>
        ///   of a <see cref="IWorkItem"/>.
        ///   <para>
        ///   An exception at this point leaves the <see cref="WorkQueue"/> in an inconsistent state.  The
        ///   follow actions are performed:
        ///   <list type="bullet">
        ///   <item><description>The queue is <see cref="Pause">paused</see></description></item>
        ///   <item><description>The <see cref="WorkerException"/> event is raised.</description></item>
        ///   <item><description>All threads calling <see cref="WaitAll"/> will receive the exception.</description></item>
        ///   </list>
        ///   </para>
        /// </remarks>
        public void HandleResourceException(ResourceExceptionEventArgs e)
        {
            lock (completed)
             {
            Pause();
            internalException = e.Exception;

            // Tell the world.
            OnWorkerException(e);

            // Wakeup any threads in WaitAll and let them throw the exception.
            Monitor.PulseAll(completed);
             }
        }