CWorkerThread Class

This class creates a worker thread or uses an existing one, waits on one or more kernel object handles, and executes a specified client function when one of the handles is signaled.

Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

template < 
class ThreadTraits= DefaultThreadTraits 
> 
class CWorkerThread

Parameters

Members

Protected Structures

Name

Description

WorkerClientEntry

Public Constructors

Name

Description

CWorkerThread::CWorkerThread

The constructor for the worker thread.

CWorkerThread::~CWorkerThread

The destructor for the worker thread.

Public Methods

Name

Description

CWorkerThread::AddHandle

Call this method to add a waitable object's handle to the list maintained by the worker thread.

CWorkerThread::AddTimer

Call this method to add a periodic waitable timer to the list maintained by the worker thread.

CWorkerThread::GetThreadHandle

Call this method to get the thread handle of the worker thread.

CWorkerThread::GetThreadId

Call this method to get the thread ID of the worker thread.

CWorkerThread::Initialize

Call this method to initialize the worker thread.

CWorkerThread::RemoveHandle

Call this method to remove a handle from the list of waitable objects.

CWorkerThread::Shutdown

Call this method to shut down the worker thread.

Remarks

To use CWorkerThread

  1. Create an instance of this class.

  2. Call CWorkerThread::Initialize.

  3. Call CWorkerThread::AddHandle with the handle of a kernel object and a pointer to an implementation of IWorkerThreadClient.

    – or –

    Call CWorkerThread::AddTimer with a pointer to an implementation of IWorkerThreadClient.

  4. Implement IWorkerThreadClient::Execute to take some action when the handle or timer is signaled.

  5. To remove an object from the list of waitable objects, call CWorkerThread::RemoveHandle.

  6. To terminate the thread, call CWorkerThread::Shutdown.

Requirements

Header: atlutil.h

See Also

Reference

DefaultThreadTraits

IWorkerThreadClient Interface

Concepts

Multithreading: Creating Worker Threads

Other Resources

ATL Classes