How to make delegate fire on main thread?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

I have a worker thread that receives messages from a socket and puts
them in a queue (it sits inside a "while true") loop.

Each time it adds a message to the queue, I need the main thread to
pull a message off the queue and process it. Because it manipulates
GUI controls I need the main thread to do the dequeue and not the
worker thread.

Is there a way to make an event fire for the main thread instead of
the thread that's firing the event?

I thought about making the main application Monitor the queue, but
then the application events (like clicks on buttons) wouldn't happen.
Right?

Thanks,
John
 
If your main thread is a WindowsForm, use the Control.Invoke method of your
main form.

Dale
 
Hello John,

How is everything going? Have you successfully resolved the problem by
using Dale's suggestion? If there is any we can do, please feel free to
post here.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello John,

How is everything going? Have you successfully resolved the problem by
using Dale's suggestion? If there is any we can do, please feel free to
post here.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Yes, Dale's suggestion helped.

Thanks,
John
 
Back
Top