System.Windows.Forms.Timer.Reset() ???

M

mikeachamberlain

Hello.

Why is there no Reset() method on the windows forms timer? Calling
Start() then Stop() only disables the raising of events for this
period. It doesn't reset the timer back to 0. For instance, I have a
timer that elapses every 30 seconds, let it run for 10 seconds, stop it
for 10 seconds, then start it again, the next is event is raised in
another 10 seconds, instead of 30 seconds as I'd expect it to be.

I know I can work around it, which involes adding a DateTime variable
to my page, setting it, and using a timer to check it against the
current time. However, this is pretty annoying.

Why no Reset() method?

Mike
 
S

Stoitcho Goutsev \(100\)

Mike,

I believe the windwos form timer works exactly how you expected. When you
srart the timer it raises the event after the period of time the timer is
set up with.

You correctly expect the timer to come after 30 sec again.

I created a test application and tested your scenario - I started the timer,
let it run for 10 sec, stopped it, waited 10 sec, started it again. The tick
even came 30 sec after I started for the second time.

I believe you are doing something wrong there. Make sure that you call Stop
or set Enabled to false. If you call two times Start in a row the second
start doesn't reset the timer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top