c# - timer application not running properly -
i writing simple c# application, in program counts 15 seconds , outputs "15" 15 seconds have passed. although, program works fine first few trials, starts freeze instead. know why? , how can improve it?
public void timer() { time.text = "restart"; int = 0; datetime st1 = datetime.now; string time1 = st1.second.tostring(); int timef = convert.toint32(time1); int timef2; while (i < 15) { datetime st2 = datetime.now; string time2 = st2.second.tostring(); timef2 = convert.toint32(time2); = timef2 - timef; } time.text = i.tostring(); = 0; }
you need use timer
if want application perform actions after specific amount of time
.
system.timers.timer timer = new system.timers.timer(); timer.interval = 15 * 1000; timer.elapsed += timer_elapsed; timer.start(); int timercount=0; void timer_elapsed(object sender, eventargs e) { timercount++; int timeelapsed = timercount * 15; }
Comments
Post a Comment