Delegates & Events

  • Thread starter Thread starter Kyle Jedrusiak
  • Start date Start date
K

Kyle Jedrusiak

I need some clarrification.

I have a class called ChatManager that will manage the interaction between
the ClientUI (WinForm) and the chat server.

The ChatManager will have a number of public events.

When the ClientUI is instantiated it will subscribe to these events
providing its own methods to be used as event handlers.

In the ChatManager code when I raise a particular event...which in turn
calls the delegate...

Will the delegate execute on the same thread as the ClientUI (which it must
do to update the WinForm) or does it execute on some other thread?

Kyle!
 
Hi Kyle,
Will the delegate execute on the same thread as the ClientUI (which it must
do to update the WinForm) or does it execute on some other thread?

No, the delegates will execute on the calling thread. ClientUI has to
schedule the code for updating the UI to be executed by the UI thread. Since
it's a WinForm control it has no problems to do that via calling either
Control.Invoke or Control.BeginInvoke.
 
Back
Top