Re: PostMessage and unprocessed messages
"Tom Serface" <tom.nospam@camaswood.com> ha scritto nel messaggio
news:A58A0684-7C04-4301-96A7-0D036643E6DF@microsoft.com...
I typically have a volatile bool in my thread that I can access through a
getter function from my GUI class. That way I can check it to see when
the thread is done after I get the notification message. I set the bool
right after exiting the thread loop. The procedure works well for me.
Hi Tom,
my problem is that I'm having pending messages sent from the background
worker thread to the main GUI thread (dialog-box).
These messages are carrying dynamically allocated data, that I must delete
if I don't want memory leaks.
If these pending messages required no deletion of dynamically allocated
data, I would be happy to just discard and ignore them, but I must process
them (also if the thread has finished its lifetime) just to call delete on
the pointer stored in LPARAM.
Having the boolean signaling the thread is done is one part of the job, but
there is more.
In fact, in the WMU_WORKER_PROGRESS custom message handler, I can do
void OnWorkerProgress( ... )
{
MessageData * data = (MessageData)lParam;
if ( thread is alive )
{
... process data
}
// Delete dynamically allocated data (created using 'new' by the worker
thread)
delete data;
}
I don't want non-processed pending WMU_WORKER_PROGRESS messages in the
message queue, because this would mean leaking memory allocated by the
worker thread.
G