Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / Visual Basic

Generic Wrapper for Easy Multithreaded Programming

Rate me:
Please Sign up or sign in to vote.
4.94/5 (34 votes)
2 Jun 2014CPOL14 min read 75.4K   710   126  
Event-based, generic wrapper and manager to implement multithreading in your applications
using System;

namespace SIGLR.Async.GenericWrapper.Worker
{

    /// <summary> 
    /// Worker interface (without any generics) 
    /// </summary> 
    /// <remarks></remarks> 
    public interface IWorker
    {

        #region "Properties"

        /// <summary> 
        /// Used between AsyncManager and WorkerBase, to become AsyncManagerTyped 
        /// </summary> 
        /// <returns>The handle to the parent async manager</returns> 
        /// <remarks></remarks> 
        object AsyncManagerObject
        {
            get;
            set;
        }

        /// <summary> 
        /// Used by the derived worker class to check if an interruption request was received 
        /// </summary> 
        /// <returns>Flag that indicates if an interruption request was received</returns> 
        /// <remarks></remarks> 
        bool InterruptionRequested
        {
            get;
        }

        /// <summary> 
        /// Used to hold the results of the worker, as object 
        /// </summary> 
        /// <returns>Worker result</returns> 
        /// <remarks></remarks> 
        object ResultObject
        {
            get;
        }

        /// <summary> 
        /// Used to hold the exception (if any) that occurred in the worker 
        /// </summary> 
        /// <returns>Exception (if any) that occured in the worker</returns> 
        /// <remarks></remarks> 
        Exception WorkerException
        {
            get;
        }

        #endregion

        #region "Subs and Functions"

        /// <summary> 
        /// Called by the AsyncManager to start the worker in asynchronous mode 
        /// </summary> 
        /// <remarks></remarks> 
        void StartWorkerAsynchronous();

        /// <summary> 
        /// Called by the AsyncManager to start the worker in synchronous mode 
        /// </summary> 
        /// <remarks></remarks> 
        void StartWorkerSynchronous();

        /// <summary> 
        /// Called by the AsyncManager to stop the worker (interruption request) 
        /// </summary> 
        /// <remarks></remarks> 
        void StopWorker();

        #endregion

    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Services Informatiques GLR Inc.
Canada Canada
I'm an independant software architect working as consultant for various companies in the region of Quebec City, Canada.

I have close to 20 years of experience in development of applications and systems of various scales, in many different lines of business.

Since 2003, I have exclusively worked in .NET projects, switching roles from senior designer to lead designer and software architect. I have also contributed to the development of the Web Service Software Factory (WSSF) from Microsoft's Patterns and Practices team, as adviser.

Comments and Discussions