How do I use a timer and a numericUpDown?
Hi I was wondering how do I use a timer and a numericUpDown that specifies the amount of seconds?
I just need the timer to make my program not do anything for a few seconds (but not freeze the interface) so I assume I wouldnt need to use the timer_tick event.
Do you guys know how to do this?
Re: How do I use a timer and a numericUpDown?
The timer will not do what you seem to be wanting. A timer fires an event every x milliseconds. Other objects continue to run as usual. To make to program stop for a period of time you would need to use the Sleep method of the Threading class.
Re: How do I use a timer and a numericUpDown?
I tried this but it doesnt seem to be waiting the amount of time I specify in the numericUpDown:
Code:
timer1.Interval = Convert.ToInt32(numericUpDown2.Value * 1000);
timer1.Start();
Re: How do I use a timer and a numericUpDown?
I am testing this with a webBrowser, and want it to stop doing anything for the specified amount of time but even with the timer on, nothing stops
Re: How do I use a timer and a numericUpDown?
Re: How do I use a timer and a numericUpDown?
As I said a timer does not stop execution of your program. A timer fires an event every x milliseconds. If you wanted something to happen say in 30 seconds you could use a timer and place the code in the timer 30 seconds after the timer is enabled the code would execute. Other code will execute as it normally would timer will have no effect. To halt execution of code you must use Sleep. You can use a loop to keep code from going on but that is not always such a good idea.
A timer will not do what you wish.
Re: How do I use a timer and a numericUpDown?
Oh :o, thanks for clearing that up.
Also, doesnt sleep freeze the whole gui?
Re: How do I use a timer and a numericUpDown?
Sleep freezes the thread that it is called on. If it is called on the GUI thread then yes it will freeze the GUI