How to make delegate fire on main thread?

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
 
D

DalePres

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

Dale
 
Y

Yan-Hong Huang[MSFT]

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.
 
J

John

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
 

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