Re: Timer Tick Event not Working in Windows Service

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jay B. Harlow [MVP - Outlook] (Jay_Harlow_MVP_at_msn.com)
Date: 07/13/04


Date: Tue, 13 Jul 2004 17:34:25 -0500

J.
In addition to the other comments.

In addition to the others comments, the following articles in MSDN Magazine
explain the difference between the three timer objects in .NET & when to use
each.

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx

http://msdn.microsoft.com/msdnmag/issues/04/03/default.aspx

The above articles also discusses if & how each timer interacts with
threading.

I'm using System.Timers.Timer (instead of System.Threading.Timer) in my
Windows Service, as I don't really need the extra features of
System.Threading.Timer. Either should work in your case.

Hope this helps
Jay

"J. Hill" <J. Hill@discussions.microsoft.com> wrote in message
news:C78F64BF-BE17-43E4-BF68-8532307A53D4@microsoft.com...
> I have a Windows Service with a timer but the .Tick event is not being
fired/called.
>
> Don't know what code to include...I enabled and started the timer...I have
the exact same code in a Windows form and it works fine, but in the service:
nothing.
>
> ...
> this.components = new System.ComponentModel.Container();
> this.tmrTimer = new System.Windows.Forms.Timer(this.components);
> //
> // tmrTimer
> //
> this.tmrTimer.Interval = 6;
> this.tmrTimer.Tick += new System.EventHandler(this.tmrTimer_Tick);
>
> ...
>
> //In OnStart or Initialization -- tried both...
> tmrTimer.Start();
> tmrTimer.Enabled = true;
> /*
> also tried
> tmrTimer.Enabled = true;
> tmrTimer.Start();
> */
> ...
> private void tmrTimer_Tick(object sender, System.EventArgs e) {
> tCurrTime = DateTime.Now;
> EventLog.WriteEntry("Timer Tick", "We have ticked...",
> EventLogEntryType.Error);
>
> if (tCurrTime.Hour == 0){
> DoMidNightService();
> }
>
>
>
>
> Even a "did you check this" would be a great help.
>
> Thanks,
> J.



Relevant Pages

  • Re: Form Status Controls Stop Updating if Form Loses Focus
    ... I bet you're using a timer to update with... ... It's independent of the Forms message pump ... and so will fire even when the form is not pumping messages. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Timer Tick Event not Working in Windows Service
    ... I had just 'migrated' my code from my development Windows app and brought the timer code over. ... > In addition to the others comments, the following articles in MSDN Magazine ... > Windows Service, as I don't really need the extra features of ...
    (microsoft.public.dotnet.languages.csharp)
  • Need info on Windows Timers
    ... How exactly Windows executes the timer callback. ... From the articles I read, ... As we know the thread dispatcher/scheduler is the most critical part of ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Calling Paint
    ... invoke Invalidate accordingly. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... >I have a usercontrol with a timer on it. ...
    (microsoft.public.dotnet.framework.drawing)
  • Windows Service and timers madness
    ... timers, spcifically in Windows Services ... service, the timer events never fire, so the code never executes. ... Windows FORMS tab, which I did. ... In the articles I have read, its also important to use the Timer_Elapsed ...
    (microsoft.public.dotnet.languages.vb)