Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Starting and stopping a Threading.Timer
Message
De
01/10/2008 15:49:27
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
01/10/2008 15:40:28
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01352099
Message ID:
01352101
Vues:
19
I found the answer here:
http://www.yoda.arachsys.com/csharp/threads/timers.shtml

I wish I had found this before I posted (bg).
Tim

>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform