Win Service & Timer

  • Thread starter Thread starter Rajesh Abraham
  • Start date Start date
R

Rajesh Abraham

I have a timer in my Windows Service project and I am
trying to do some processing on the tick event of the
timer but this event does not seesms to be raised. Below
is some code segment. Any Idea?

Thanks,

Rajesh Abraham

-----Code Below------

private void InitializeComponent()
{
this.components = new
System.ComponentModel.Container();
this.timerTerminator = new
System.Windows.Forms.Timer(this.components);
//
// timerTerminator
//
this.timerTerminator.Enabled =
true;
this.timerTerminator.Tick += new
System.EventHandler(this.timerTerminator_Tick);
//
// TerminatorService
//
this.ServiceName = "TermSrv";

}



private void timerTerminator_Tick(object sender,
System.EventArgs e)
{

System.IO.File.Create(@"c:\timertick.txt");

TerminatorBis.Terminate();
}
 
Hi,

I would use the System.Timers.Timer
instead of System.Windows.Timer the latter is intended to be used with
windows forms, and if the memory do not fail me I think that I also had my
troubles dealing with it and a window service.

Two other things:
1- The event of the System.Timers.Timer is different that the one from
system.windows:
timer.Elapsed += new ElapsedEventHandler( ... )
2- Use the timer.Start() or Enabled=true to start raising the Elapsed event.

Hope this help,
 
Back
Top