Question about Multithreading

G

Guest

Hello everyone,
I am implementing a multithreaded tcp client with two classes,
cNetworkManager class and cUI Class, I created a secondary thread for
receiving packets using blocking "Receive" method in cNetworkManager and when
a packet is received I want to raise an event to cUI Class, but I don't want
to raise that event on my secondary thread, so does anyone know how can I
notify my main thread in cNetworkManager so the thread could raise the event
for cUI class.

Regards,
 
J

Jon Skeet [C# MVP]

Jefe said:
I am implementing a multithreaded tcp client with two classes,
cNetworkManager class and cUI Class, I created a secondary thread for
receiving packets using blocking "Receive" method in cNetworkManager and when
a packet is received I want to raise an event to cUI Class, but I don't want
to raise that event on my secondary thread, so does anyone know how can I
notify my main thread in cNetworkManager so the thread could raise the event
for cUI class.

You'll need to use an ISynchronizeInvoke reference to call
Invoke/BeginInvoke/EndInvoke on. UI controls all implement this
automatically, but you'll need to pass it to the NetworkManager class
(eg in the constructor) so that it's got something to communicate with.

Jon
 
G

Guest

Hi Jon,
Tnx for the reply, could you give a code sample or a url which has the sample?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top