Win Service & Timer

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();
}
 
D

Dan Cimpoiesu

Try using the Timer class from System.Threading

Hope this helps
Dan Cimpoiesu
 
I

Ignacio Machin

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,
 

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