|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
System.Timers.TimerHi all
Is it true that System.Timers.Timer runs on a seperate thread, using the thread pool. if so, it means that the elapsed callback will never be on the context that the timer was created in. What do i have to do to achieve that : receive the elapsed event handler in the thread that created the timer. Regards Shayke Yes, Elapsed callback will be executed on the separate thread.
Why do you need such behavior? Have you checked System.Windows.Forms.Timer? Show quote "shayke" <sh***@aeronautics-sys.com> wrote in message news:OfrWoljCGHA.984@tk2msftngp13.phx.gbl... > Hi all > > Is it true that System.Timers.Timer runs on a seperate thread, using the > thread pool. > if so, it means that the elapsed callback will never be on the context > that the timer was created in. > What do i have to do to achieve that : receive the elapsed event handler > in the thread that created the timer. > > Regards > Shayke > Hi Vadym
Thanks for your reply. My need for the timer to callback in it's creator thread comes from a bigger need. i have been trying (with no luck) to execute code on specific thread context.something like SynchronizationContext does BUT for any thread and not just the UI thread. Have you any idea how i can achieve that? Regards Shay *** Sent via Developersdex http://www.developersdex.com *** shay azulay <sh***@aeronautics-sys.com> wrote:
> Thanks for your reply. Well, what else is this thread doing? You can't make one thread just > My need for the timer to callback in it's creator thread comes from a > bigger need. > i have been trying (with no luck) to execute code on specific thread > context.something like SynchronizationContext does BUT for any thread > and not just the UI thread. > Have you any idea how i can achieve that? hijack another - the thread you want to run code on needs to be "looking" for the work to do. Something like the UI message pump, or a producer consumer queue. For an example of the latter, see http://www.pobox.com/~skeet/csharp/threads/deadlocks.shtml (half way down). -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Hi Shayke,
"shayke" wrote: Depends on the SynchronizingObject property of the Timer instance. > Hi all > > Is it true that System.Timers.Timer runs on a seperate thread, using the > thread pool. > if so, it means that the elapsed callback will never be on the context that > the timer was created in. > What do i have to do to achieve that : receive the elapsed event handler in > the thread that created the timer. > > Regards > Shayke From MSDN. <quote> When SynchronizingObject is a null reference (Nothing in Visual Basic), the method that handles the Elapsed event is called on a thread from the system-thread pool. For more information on system-thread pools, see ThreadPool. When the Elapsed event is handled by a visual Windows Forms component, such as a button, accessing the component through the system-thread pool might result in an exception or just might not work. Avoid this effect by setting SynchronizingObject to a Windows Forms component, which causes the method that handles the Elapsed event to be called on the same thread that the component was created on. </quote> Kind regards, -- Tom Tempelaere. |
|||||||||||||||||||||||