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!

Timer class - is it independently repeating?

Status
Not open for further replies.

Kenny100

Technical User
Feb 6, 2001
72
NZ
Hi Folks

I've got a class called Timer with the following code:

public class Timer
{
public static void Main(String[] args)
{
System.Timers.Timer aTimer = new System.Timers.Timer();

aTimer.Elapsed += new ElapsedEventHandler(OnTimer);
aTimer.Interval = 10000;
aTimer.Enabled = true;

Console.WriteLine("Press \'q\' to quit the timer");
while(Console.Read()!='q');
}

public static void OnTimer(Object source, ElapsedEventArgs e)
{
CopyFiles MyCopyFiles = new CopyFiles(); // Create instance
MyCopyFiles.CheckDir();
}
}

As you can see, every 10 seconds the timer calls the CheckDir method in the CopyFiles class. My question is this: does the Timer class call this method and then WAIT until the method has finished running before carrying on OR does the Timer simply call the method after EVERY 10 seconds? I'm a bit confused!

If the latter is the case, I'd like to be able to pause the timer while the CheckDir method is running. Any ideas on how I can do this?

Thanks for any help,
Kenny.
 
Programming is a step-by-step method. So, the OnTimer EventHandler fires, then, once the OnTimer EventHandler is done, the sequence is continued and the timer waits for ten seconds before continuing on. So the timer is not running until the OnTimer is done and returns control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top