Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitoring elapsed time with the stop watch

Status
Not open for further replies.

steve1rm

Programmer
Aug 26, 2006
255
GB
Hello,

I am developing a windows service in VS 2005 that will monitor time and do something every 5 seconds.

I have created some code using the stopwatch class. Can anyone tell me if this is the best way to do this .

Code:
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
sw.Start();
this.RunningTime();
}

protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
sw.Stop();
}

private void RunningTime()
{
if (sw.IsRunning)
{
if (sw.Elapsed.Seconds == 5)
{
//Do something here
}
}
}

Many thanks in advance,

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top