473,472 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to make delegate fire on main thread?

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
Nov 16 '05 #1
3 2367
If your main thread is a WindowsForm, use the Control.Invoke method of your
main form.

Dale

"John" <jo********@hotmail.com> wrote in message
news:d8*************************@posting.google.co m...
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

Nov 16 '05 #2
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.

Nov 16 '05 #3
yh*****@online.microsoft.com (Yan-Hong Huang[MSFT]) wrote in message news:<4j**************@cpmsftngxa10.phx.gbl>...
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
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
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...
0
by: Ginno | last post by:
Hello all Within my reports form i have used delegates to allow a crystall reports to generate without holding up the user. The user selects a report from tree view, enters the appropriate...
2
by: cmrchs | last post by:
Hi, how can I call a method, being referenced by a delegate object, via a thread ? Here's what I try : public delegate void PrintDelegate(); static void Print() {...
0
by: Paul Tomlinson | last post by:
Morning all. Let me describe my problem. Main thread creates child objects and threads and starts them Timer on the main thread (which only gets activated after the child threads have started)...
2
by: Nony Buz | last post by:
My objective is simply: Notify a form when a image file has been created in a directory. First there is a basic interface for the callback function: public interface INewImageNotify { void...
4
by: pz0071 | last post by:
G'day, I think I got my head around using delegates, particularily when updating the user interface from another thread. I got it all sussed, just not 100% sure on the correct syntax for...
9
by: Terry Olsen | last post by:
I'm running an asynchronous Socket. In the ReceiveCallback method, I need to append what is received to a textbox on the main form. I have this code: Private Sub ToChatWindow(ByVal msg As...
5
by: greg.merideth | last post by:
I have a class that I've provided an event for to be called when the processing in the class is complete (a callback). The class spins up a series of threads for the background operation and I'm...
11
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke...
5
by: jecheney | last post by:
Hi, another thread, Debug_Console is a listbox control on my main form, i created the delegate to avoid the cross threading error. Now the strange thing is, when i call the method from my other...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.