Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using visual basic 2010 on .net framework 4 and im have an issuing creating a simple count down timer. i was wondering if anyone new the simplist method to create a countdown timer in milliseconds or seconds using a timer control and intervals.

I currently have a form with 1 textbox and 1 timer control. i want the textbox display a countdown in milliseconds from interval of 300000 (5mins).

Any help or direction would be helpful.

Cheers Tom
Posted

I agree with John about his evaluation of thread vs timer.
See also my past answer:
Timer Threading in C#[^]

If you really need a timer, any of the other types of Timer:
System.Threading.Timer or System.Timers.Timer, see:
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx[^].

However, you cannot call anything on UI from the timer's callback delegate or event handler. Instead, you need to call the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (both Forms or WPF) or System.Windows.Forms.Control (Forms only).

For detailed explanations of the invocation and code samples, please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

—SA
 
Share this answer
 
Comments
SIFNOk 12-Jun-11 17:53pm    
SA - Thank you sooo much for these References, actually reall awesome information! and like you said can be implemented at any level of experiences! I like the uses of a dispatch timer =D thanks you soo much for your input it has helped me much and giving me an insight into something i can probally get a hang of myself.....5 votes from me.
Sergey Alexandrovich Kryukov 12-Jun-11 18:04pm    
You're welcome.
Thanks for accepting this answer.
Good luck, call again.
--SA
Don't use the Winforms Timer control. Use System.Timers.Timer instead. Of course, if it were me, I'd use a thread and a delegate instead of ANY Timer object because

0) You have more control

1) The Windows Timer even is the lowest priority message in Windows and on a busy system, it's NOT guaranteed to be processed by the OS. A thread is a better choice.
 
Share this answer
 
Comments
SIFNOk 12-Jun-11 8:14am    
Thanks John For Your Reply, I Appericate your help!

i have read that timers are very unreliable for scheduling and timer purposes and that system.threading is a better method...but my vb.net skills are not best so my knowledge on implementing threading soo not too good....im have alook on MSDN now about system.thread but if you nay information of other references that could help me would be great :)

but would i still be able to achieve a count down timer using a timer control?
Sergey Alexandrovich Kryukov 12-Jun-11 15:29pm    
At ***any level of skills* threads are easier to implement!
--SA
Sergey Alexandrovich Kryukov 12-Jun-11 15:45pm    
Agree, my 5.
However, in case the timer is still needed (it can be needed in rare cases), I put a detailed answer, please see.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900