Hi all,
I use System.Windows.Forms.Timer with a Windows service but nothing happens
after given interval elapsed. It seems timer event does not occur. How can
I use timers with Windows Services?
Thanks in advance.
Vadym Stetsyak - 21 Aug 2006 09:41 GMT
Hello, KЭrЧat!
K> I use System.Windows.Forms.Timer with a Windows service but nothing
K> happens after given interval elapsed. It seems timer event does not
K> occur. How can I use timers with Windows Services?
Take a look in System.Timers.Timer class. or
System.Threading.Timer class
In your case System.Windows.Forms.Timer is not working, because you do not
have message loop and this type of timer uses WM_TIMER windows message
to operate...
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Kursat - 21 Aug 2006 10:56 GMT
Thanks Vadym, worked well.
> Hello, Kürþat!
>
[quoted text clipped - 12 lines]
> Regards, Vadym Stetsyak
> www: http://vadmyst.blogspot.com
Marc Gravell - 21 Aug 2006 09:45 GMT
I must adimit I've never tried to use winform timers in a service, so I
can't say if it is possible - *but* you could perhaps switch to
System.Timers.Timer? Just watch out that the Elapsed event is fired on
a different thread, so you may need to do your own thread sync code.
And note that you will need to kill the timer yourself at the end, as
there is no form to host it and manage its lifetime (although I /guess/
you could just let it get torn down at AppDomain unload, but I like to
be tidy ;-p).
Any use?
Marc
Kürsat - 21 Aug 2006 10:59 GMT
Synchronization requirement is a good point to care about. Thank you.
>I must adimit I've never tried to use winform timers in a service, so I
> can't say if it is possible - *but* you could perhaps switch to
[quoted text clipped - 8 lines]
>
> Marc