Cross Thread Event Handling

  • Thread starter Thread starter Rob P
  • Start date Start date
R

Rob P

Hi all,

I am working on a mesaging system at the moment which
currently uses at least two threads, one the main client
interface, and the second (or more) providing a
network/message listener.

The project works and is happily providing the required
functionality, but the users of the system are unhappy
about having to handle concurrency issues (Mainly to do
with UI updates) in their code, due to the fact that when
an event is thrown from the listener (e.g. You have a new
message from the server, or the network is now unavailable
etc.) to the client interface and upwards, the event is on
the same thread as the listner and not the client.

Is there some way of throwing events to a different thread
within an application? Or some way of listening for these
messages on the same thread as the client thread? Or can I
pass a callback pointer to the new thread that it can call?

Any help would be great.

Cheers

Rob P
 
Hi Rob,

You might do something like this in event implementation.

if (InvokeRequired())
Invoke(the same event)
else
{
do the UI code
}
 
Back
Top