|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Timers run on the creating thread?Do timers run on the same thread that creates them or (internally) a
new thread is spawned per timer? Water Cooler v2 wrote:
> Do timers run on the same thread that creates them or (internally) a It depends on which Timer you are referring to. If it is the Timer> new thread is spawned per timer? within System.Windows.Forms, then it'll run on the UI thread. If it's the Timer within System.Threading, then I believe it runs in another thread. Whether this thread is newly created, or from the thread pool, or from some internal pool, I'm not sure. But I'm fairly certain it won't be the original thread. After all, the original thread has carried on, and could be in any state when the timer elapses (e.g. it might be in the middle of a multi-second database call) Damien The System.Threading timer events are executed from a Thread Pool thread.
Mike Ober. Show quote "Damien" <Damien_The_Unbelie***@hotmail.com> wrote in message news:1152613059.725941.34710@s13g2000cwa.googlegroups.com... > Water Cooler v2 wrote: > > Do timers run on the same thread that creates them or (internally) a > > new thread is spawned per timer? > > It depends on which Timer you are referring to. If it is the Timer > within System.Windows.Forms, then it'll run on the UI thread. If it's > the Timer within System.Threading, then I believe it runs in another > thread. Whether this thread is newly created, or from the thread pool, > or from some internal pool, I'm not sure. But I'm fairly certain it > won't be the original thread. After all, the original thread has > carried on, and could be in any state when the timer elapses (e.g. it > might be in the middle of a multi-second database call) > > Damien > > Which thread will receive the event then for the System.Threading timer.
-- Show quoteDennis in Houston "Michael D. Ober" wrote: > The System.Threading timer events are executed from a Thread Pool thread. > > Mike Ober. > > "Damien" <Damien_The_Unbelie***@hotmail.com> wrote in message > news:1152613059.725941.34710@s13g2000cwa.googlegroups.com... > > Water Cooler v2 wrote: > > > Do timers run on the same thread that creates them or (internally) a > > > new thread is spawned per timer? > > > > It depends on which Timer you are referring to. If it is the Timer > > within System.Windows.Forms, then it'll run on the UI thread. If it's > > the Timer within System.Threading, then I believe it runs in another > > thread. Whether this thread is newly created, or from the thread pool, > > or from some internal pool, I'm not sure. But I'm fairly certain it > > won't be the original thread. After all, the original thread has > > carried on, and could be in any state when the timer elapses (e.g. it > > might be in the middle of a multi-second database call) > > > > Damien > > > > > > > > The callback is run on a ThreadPool thread. What event are you referring
to? tia -- Show quoteWilliam Stacey [MVP] "Dennis" <Den***@discussions.microsoft.com> wrote in message news:1F70A605-8E21-432B-83D0-497012D52AD7@microsoft.com... | Which thread will receive the event then for the System.Threading timer. | -- | Dennis in Houston | | | "Michael D. Ober" wrote: | | > The System.Threading timer events are executed from a Thread Pool thread. | > | > Mike Ober. | > | > "Damien" <Damien_The_Unbelie***@hotmail.com> wrote in message | > news:1152613059.725941.34710@s13g2000cwa.googlegroups.com... | > > Water Cooler v2 wrote: | > > > Do timers run on the same thread that creates them or (internally) a | > > > new thread is spawned per timer? | > > | > > It depends on which Timer you are referring to. If it is the Timer | > > within System.Windows.Forms, then it'll run on the UI thread. If it's | > > the Timer within System.Threading, then I believe it runs in another | > > thread. Whether this thread is newly created, or from the thread pool, | > > or from some internal pool, I'm not sure. But I'm fairly certain it | > > won't be the original thread. After all, the original thread has | > > carried on, and could be in any state when the timer elapses (e.g. it | > > might be in the middle of a multi-second database call) | > > | > > Damien | > > | > > | > | > | > | > |
|||||||||||||||||||||||