Hi Everyone,
I am developing some online examination.In that i need to fire count down timer in a label.The time will calculated by
system itself,by depending on the no of questions present in SQL server.How can i implement this on windows application.
Thanks & Regards,
M.Mahesh
Loading
Sam HobbsPosted Sep 20, 2011, 6:01 PM
I assume this is for a Windows Forms application. So you can use the Timer Class in the System.Windows.Forms Namespace. I assume you want the countdown to update every second. So you can set the timer for an interval of one second and then for every tick, change the time remaining; when the time remaining is zero then you know that the time is up.
That however could easily become inaccurate. The Windows timer is not guaranteed to be precise. So what you should do is to set the timer to tick after a second and then in the tick handler cancel the timer, calcualte how many microsseconds until the next second, and start the timer again for that interval. You want to do that so that if Windows does not have a chance to call the timer tick handler at the precise time, your code will automaticallly adjust.