Execute a timed Command
is there a way to execute a command every x period of time?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Aug 19, 2009, 11:17 AM EDT
here is some sample code for both:
Using System.Threading:
ublic class MyClass { System.Threading.Timer Timer; System.DateTime StopTime; public void Run() { StopTime = System.DateTime.Now.AddMinutes(10); Timer = new System.Threading.Timer(TimerCallback, null, 0, 5000); } private void TimerCallback(object state) { if(System.DateTime.Now >= StopTime) { Timer.Dispose(); return; } // do your work..... } }using a loop: