"Posting" to GUI Thread from Background Thread

C

C# Learner

I'm working on an app which uses a background thread to read data from
a socket.

At the moment I'm doing something a bit "naughty" -- I'm firing an
event after reading from the socket, and this event gets picked up by
an event handler in the GUI thread, without "synchronizing" with this
GUI thread.

How can I "synchronize" threads in .NET?
 
J

Jon Skeet [C# MVP]

C# Learner said:
I'm working on an app which uses a background thread to read data from
a socket.

At the moment I'm doing something a bit "naughty" -- I'm firing an
event after reading from the socket, and this event gets picked up by
an event handler in the GUI thread, without "synchronizing" with this
GUI thread.

How can I "synchronize" threads in .NET?

Use Control.Invoke to run a delegate in the GUI thread associated with
a specific control.
 

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