Firing events on another thread

  • Thread starter Thread starter joe
  • Start date Start date
J

joe

Hi,

My program communicates with the serial port and shows
some information on the screen. The communication class
creates a separate thread for reading from the port. If a
character is received, an event is fired from the thread.

public event CharacterReceived;
private void ReceiveThread()
{
...
if (CharacterReceived!=null)
{
CharacterReceived(...)// notify subscribers
}
}

The subscribers of this event are controls (forms and user
controls). Because the handlers are called on
ReceiveThread, all the UI function in the handlers must be
called with BeginInvoke. Cant I, instead of tracing all
these functions and making them thread-safe, just fire
CharacterReceived on the UI thread somehow

Thanks
 
Hi,

I'm afraid that there is at least no simple way. I'd therefore suggest
sticking to BeginEnvoke.
 
Back
Top