CMsgThread class

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The CMsgThread class is a worker-thread class that queues requests to the queuing thread for completion asynchronously. To use this class, derive your class from it and override the CMsgThread::ThreadMessageProc member function. The ThreadMessageProc member function carries out each request. Your client functions and the ThreadMessageProc member function must share a common definition of the parameters in the CMsg object.

A negotiated mechanism tells the worker thread to exit. Typically, this will be one value of the CMsg class's uMsg message code.

It is a good idea to send this message from the destructor of your derived class, and call the CMsgThread::WaitForThreadExit member function before completing the destruction of the derived class.

Protected Data Members Description
m_hSem Indicates a handle used for signaling.
m_Lock Protects access to lists.
m_lWaiting Indicates waiting for a free thread.
m_ThreadQueue Overrides the CMsgThread::GetThreadMsg member function and blocks on things other than this queue.
Member Functions Description
CMsgThread Constructs a CMsgThread object.
CreateThread Creates a thread.
GetThreadHandle Retrieves the thread handle.
GetThreadID Retrieves the identifier of the thread.
GetThreadPriority Retrieves the current thread priority.
PutThreadMsg Queues a request for execution by the worker thread.
ResumeThread Continues the operation of the worker thread.
SetThreadPriority Sets the priority of the thread to a new value.
SuspendThread Suspends the operation of a running thread.
WaitForThreadExit Blocks until the thread has exited after a call to the CMsgThread::SuspendThread member function.
Overridable Member Functions Description
GetThreadMsg Retrieves a queued CMsg object containing a request.
OnThreadInit Provides initialization on a thread.
ThreadMessageProc Processes requests. This is a pure virtual member function.