Click here to Skip to main content
15,885,244 members
Articles / Desktop Programming / MFC

WorkerThread Library

Rate me:
Please Sign up or sign in to vote.
4.00/5 (4 votes)
7 Nov 20054 min read 57.5K   990   35  
An article on a generic WorkerThread library.
#ifndef _WORKERTHREAD_H_
#define _WORKERTHREAD_H_

#include <Afxwin.h>

extern const UINT DO_WORK;
const int TIMEOUT_PER_THREAD = 200;

/**
 *
 * WorkerThread - This Thread class is created by WorkerThreadMgr
 *                This class will perform a work using WorkItem.
 * Author :    Ethihas M
 * Date:  2005-08-28
 */
class WorkerThread : public CWinThread
{
    DECLARE_DYNCREATE(WorkerThread)

public:

    // Constructor
    WorkerThread();

    // Destructor
    ~WorkerThread();
    
    // Initialize instance of thread
    virtual BOOL InitInstance();

    // Do a specific work
    afx_msg LRESULT OnDoWork( WPARAM wParam_i, LPARAM lParam_i );

    // Exit the worker thread
    afx_msg LRESULT OnExitThread( WPARAM wParam_i, LPARAM lParam_i );

    // Check Thread is idle or not
    bool IsIdle();

    // Terminate the worker thread
    bool Terminate();

protected:

    DECLARE_MESSAGE_MAP()

private:

    // Sets the Status of the worker thread
    void SetThreadIdleStatus( bool bStatus_i );

private:

    // Holds the status of the worker thread
    volatile bool m_bIdle;

    // Critical section object for Synchronization
    CRITICAL_SECTION m_CriticalSection;
};

#endif // _WORKERTHREAD_H_

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
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions