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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi Folks I'm a bit new to C# and

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
NZ
Hi Folks

I'm a bit new to C# and I'm interested in creating a timer that continually loops every 10 seconds until a condition is true. When the condition is true I want to stop the Timer, perform an action and then restart the timer again. I've got this far:

using System;
using System.IO;
using System.Threading;
using System.Timers;

public class Timer
{
public static void Main()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimer);
aTimer.Interval = 1000;
aTimer.Enabled = true;
Console.WriteLine("Press \'q\' to quit the timer");
while(Console.Read()!='q');
}

public static void OnTimer(Object source, ElapsedEventArgs e)
{
if (Condition is true :))
{
aTimer.Enabled = false;
}
else
{
Continue ...
}
}
}

I can't seem to figure out how to stop the timer. Any ideas on what I need to be looking at?

Cheers,
Kenny.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top