Click here to Skip to main content
15,898,222 members
Articles / Programming Languages / C#

Work Queue based multi-threading

Rate me:
Please Sign up or sign in to vote.
4.96/5 (67 votes)
27 Nov 20046 min read 281.8K   8.7K   237  
Allows an application to queue work that is performed concurrently to the main thread while maintaining exception processing.
#region Copyright (c) 2004 Richard Schneider (Black Hen Limited) 
/*
   Copyright (c) 2004 Richard Schneider (Black Hen Limited) 
   All rights are reserved.

   Permission to use, copy, modify, and distribute this software 
   for any purpose and without any fee is hereby granted, 
   provided this notice is included in its entirety in the 
   documentation and in the source files.
  
   This software and any related documentation is provided "as is" 
   without any warranty of any kind, either express or implied, 
   including, without limitation, the implied warranties of 
   merchantibility or fitness for a particular purpose. The entire 
   risk arising out of use or performance of the software remains 
   with you. 
   
   In no event shall Richard Schneider, Black Hen Limited, or their agents 
   be liable for any cost, loss, or damage incurred due to the 
   use, malfunction, or misuse of the software or the inaccuracy 
   of the documentation associated with the software. 
*/
#endregion

using System;

namespace BlackHen.Threading
{
	/// <summary>
	///   Provides the methods and properties to manage the scheduling of an <see cref="IWorkItem">work item</see>.
	/// </summary>
	/// <remarks>
	///   <b>IWorkQueue</b> provides the methods and properties to the manage the scheduling of an <see cref="IWorkItem"/>.
	///   Its primary responsibility is to determine when and it what order work items are executed.
	///   <para>
	///   The <see cref="WorkItemStateChanged"/> method is invoked by an <see cref="IWorkItem"/> to inform the <b>WorkQueue</b>
	///   of a <see cref="IWorkItem.State"/> change.  It is the responsible of the <b>WorkQueue</b> to
	///   perform the appropiate logic for the given state.
	///   </para>
	///   <para>
	///   </para>
	/// </remarks>
   public interface IWorkQueue
   {
      /// <summary>
      ///   Invoked by an <see cref="IWorkItem"/> to inform a work queue that its <see cref="IWorkItem.State"/>
      ///   has changed.
      /// </summary>
      /// <param name="workItem">
      ///   The <see cref="IWorkItem"/> that has changed <see cref="IWorkItem.State"/>.
      /// </param>
      /// <param name="previousState">
      ///    One of the <see cref="WorkItemState"/> values indicating the previous state of the <paramref name="workItem"/>.
      /// </param>
      /// <remarks>
      ///   It is the responsible of the <see cref="IWorkQueue"/> to  perform the appropiate logic for the 
      ///   new <see cref="IWorkItem.State"/>.
      /// </remarks>
      void WorkItemStateChanged (IWorkItem workItem, WorkItemState previousState);

      /// <summary>
      ///   Invoked by an <see cref="IResourcePool"/> 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 an <see cref="IResourcePool"/> when
      ///   an exception is thrown outside of the <see cref="IWork.Perform">normal processing</see>
      ///   of a <see cref="IWorkItem"/>.
      /// </remarks>
      /// <seealso cref="IResourcePool"/>
      void HandleResourceException(ResourceExceptionEventArgs e);
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
New Zealand New Zealand
I have been involved with computer engineering (both hardware and software) since 1975. During these almost 30 years, I have mainly been associated with start-up companies, except for a 3-year stint at Digital Equipment Corp. and 2 years at Telecom New Zealand Ltd. My positions have included Analyst, Software Engineer, R&D Manager and Director of Research and Development.

Comments and Discussions