Threads

W

WAkthar

Can someone show me how to communicate between worker threads and the main
thread?

I have a client and server application that uses sockets to transmit xml
objects. Now I need to process these xml objects in the client application.
The client application uses a listen thread to listen in for incoming
messages. Once a message has arrived in the listening thread I need to
transfer this message over to the main thread for processing and ui
updating.



Firstly is there a better way?

Secondly, how can this be done?



Thanks in advance!!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


You can use an event. In the worker thread once you did process the msg and
you are ready to update the UI you use Control.Invoke to execute an event
in the thread that created the control, the UI thread.
All your worker thread needs to know is a reference to a control, it can be
anything ( Textbox, Label, etc, etc ) you only use it to make sure that it's
executed in the UI thread.

And the approach you are using is the best one, having a worker thread
listening to the network


Cheers,
 

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