p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB.NET 2002/2003 Basics (http://p2p.wrox.com/forumdisplay.php?f=76)
-   -   Timers in a Windows Service (http://p2p.wrox.com/showthread.php?t=14328)

jaucourt June 17th, 2004 02:55 AM

Timers in a Windows Service
 
I have a fairly simple windows service I've designed, but after deploying it I found it wasn't working. After a bit of messing about I got remote debugging working, and found that the reason was that the timer wasn't ticking. I created a new service, which would write to a text file on every timer tick (once every 60,000 milliseconds, or 1 minute), and this doesn't work either.

Now the timer.enabled property defaults to false, but in the OnStart sub I set it to true and again in the OnStop I set it to false. The timer is definitely enabled, because I also put Pause and Continue routines in the first service and when stepping though these, the timer.enabled property does change (and is set to true when exiting the Continue routine).

Anyone else encountered a similar problem?


Imar June 17th, 2004 03:04 AM

Hi there,

Did you also start the timer? e.g.:

timer1.Start()

I think this method is new in .NET. In classic VB, setting it to enabled meant it would start automatically (at least I think that was the case), but in the .NET world you have to start it yourself.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Back To School by Jon & Vangelis (Track 6 from the album: The Friends Of Mr. Cairo) What's This?

jaucourt June 18th, 2004 05:31 AM

Nope, realised that I was using a System.Windows.Forms.Timer rather than a System.Timers.Timer (how stupid of me!). I can't really understand why the dot net designers thought having two timer classes that both perform in almost identical ways was a good idea, but what do I know...



All times are GMT -4. The time now is 07:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.