Re: beginners question about UI threading
- From: "Peter Duniho" <no.peted.spam@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 04 Aug 2009 12:33:36 -0700
On Tue, 04 Aug 2009 12:15:02 -0700, Colin Peters <cpeters@xxxxxxxxxxxx> wrote:
[...]
Now, I want to add a component to the mix. It is periodically polling another DB for updates and needs to inform my service when interesting changes have taken place. The polling rate is outside my concern. The component will call a callback function when a change is detected. Since the component is to function fairly autonomously I guess it runs in its’ own thread (call it Thread3), probably a MP thread because it will have to handle timer messages.
The question is: How can I detect when the callback is called? Is it possible to execute the callback in a thread other than Thread3?
My first concern is your subject text, "...about UI threading". AFAIK, a service and a UI are mutually exclusive. So it's unclear to me what you mean by "UI threading".
As far as the question itself goes, you can invoke a delegate (i.e. callback) on a specific thread in a variety of ways:
-- Where there is a Forms or WPF message pump, you can use the normal Forms or WPF mechanisms (e.g. Control.Invoke() for Forms, )
-- Alternatively, in Forms or WPF you can use a SynchronizationContext as an abstraction away from the GUI-specific mechanisms to accomplish the same thing
Absent specific support, you can implement support yourself. IMHO the simplest way is to just create a producer/consumer queue, where the thread that should be executing the delegate is the consumer, and the threads that want the delegate to be executed are the producers. Alternatively, you can write your own SynchronizationContext sub-class that does the equivalent.
I believe that in the past, there have been threads in this newsgroup regarding producer/consumer delegate queues, so Google Groups may be able to turn up useful information, including possibly one or more implementation examples.
Pete
.
- Follow-Ups:
- Re: beginners question about UI threading
- From: Colin Peters
- Re: beginners question about UI threading
- From: Peter Duniho
- Re: beginners question about UI threading
- References:
- beginners question about UI threading
- From: Colin Peters
- beginners question about UI threading
- Prev by Date: beginners question about UI threading
- Next by Date: Re: beginners question about UI threading
- Previous by thread: beginners question about UI threading
- Next by thread: Re: beginners question about UI threading
- Index(es):
Relevant Pages
|