How to make all callbacks be exectuted with the "main" thread?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

I have a class which on instantiation creates a background thread to
do its processing in. The class exposes a number of events that the
application subscribes to so that data can be reported.

How can I make it so that when my class calls an event (a callback) it
does so with the application's main thread and not with the background
thread?

My class is not a control so I can't use begin invoke, but I'd
essentially like to get the same/similar behavior.

Thanks!
John
 
If you want to pass messages/data between arbitrary threads I typically use
a signalling mechanism - one thread waits on an event that the other thread
Sets when it has new data. You don't need to do it this way on a control
because the windows message queue mechanism essentially does this for you.
 
but what if main thread have to keep running since it is taking care of UI?
you cannot put UI thread on wait and let app freeze.

.... or have I misunderstood the concept?

Gregor
 
Back
Top