Re: CWorkerThread and IWorkerThreadClient not working in my ATL COM server code

Tech-Archive recommends: Fix windows errors by optimizing your registry



Igor Tandetnik wrote:
"Edward Diener" <eddielee_no_spam_here@xxxxxxxxxxxxxx> wrote in message
news:OyX0cBzBJHA.3496@xxxxxxxxxxxxxxxxxxxx
I do not understand the AddHandle member function. I am just trying to
start a new thread on which to run my background processing.

Then just use CreateThread and be done with it. The point of CWorkerThread is you give it a handle to wait on, and some code to run once the handle becomes signalled. It's useful when you, say, have multiple asynchronous file writes or socket communications in flight at the same time: a single thread can juggle them all.

In the
AddHandle call it says it takes a waitable handle as the first
parameter. Huh ? Where does this handle come from ?

From a number of APIs that create waitable handles, of course. The documentation on WaitForSingleObject has an exhaustive list.

If I do a CreateThread I am returned a handle and can start a new
thread . How do I do the equivalent with CWorkerThread ?

I'm not sure I understand the question, but see CWorkerThread::GetThreadHandle.

The description of CWorkerThread says:

"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."

I am not interested in signaling a handle just to run my worker
thread.

Then I guess CWorkerThread is not well suited for your purposes. Obviously, you have already read the documentation, and discovered this fact. Why then do you insist on using this class?

I used _beginthreadex and everything worked properly.

Even when I tried to use the CWorkerThread with a Win32 event as the waitable handle I could not get the thread termination to be signalled in my MsgWaitForMultipleObjectsEx loop, so I obviously did not understand how to use it, or it did not work as I had assumed.

Thanks for your help.
.