Timers and delays in c#? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Timers and delays in c#?

i need a timer and a delay for a program im making in c#, ill appreciate it if you help! :)

24th Jan 2017, 7:58 PM
Toma Ristovski
Toma Ristovski - avatar
2 Answers
+ 1
What are you doing, is it a console application or in WinForms? For example a normal timer can be done like so ( Define the settings, usually in form constructor or main method ) System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent); aTimer.Interval=5000; aTimer.Enabled=true; Then just add private static void OnTimedEvent(object source, ElapsedEventArgs e) { // do something here } If you do it inside a thread you can simply do a while loop and add a Thread.Sleep(1000)* in ms There's a lot of way to do this so if you need more help just let me know.
24th Jan 2017, 8:17 PM
Alex
Alex - avatar
0
its a console application
24th Jan 2017, 8:20 PM
Toma Ristovski
Toma Ristovski - avatar