System.Windows.Forms.Timer on Windows Services

K

Kürþat

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.
 
V

Vadym Stetsyak

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
 
M

Marc Gravell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top