Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Starting and stopping a Threading.Timer
Message
From
01/10/2008 15:40:28
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Starting and stopping a Threading.Timer
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01352099
Message ID:
01352099
Views:
96
If I use a System.Windows.Forms.Timer I can stop or start the timer with:
System.Windows.Forms.Timer tmrCheckStuff = new System.Windows.Forms.Timer();
this.tmrCheckStuff.Interval = 4000; // about 4 seconds
this.tmrCheckStuff.Start;
or
this.tmrCheckStuff.Enabled = true;
If I need to stop if for a moment while something else occurs, then restart it that is pretty easy. But if I use a Threading.Timer, how do I do this?
I can issue a tmrCheckStuff.Change()
AutoResetEvent autoEvent = new AutoResetEvent(false);
TimerCallback timerDelegate = new TimerCallback(MyStuffClass.DoStuffMethod);
private System.Threading.Timer tmrCheckStuff = new System.Threading.Timer(timerDelegate, autoEvent, 90000, 5000);

I can change the time with:
autoEvent.WaitOne(5000, false);
tmrCheckStuff.Change(0, 9000);
Is there a simple way to just start and stop this timer?
Also, with the Callback how do I call a method in the same class as the timer is declared? the DoStuffMethod().
Thanks
Tim
Timothy Bryan
Next
Reply
Map
View

Click here to load this message in the networking platform