Software Development Network>> Visual C#>> Make a timer go once
How do I make a timer call only once
Your timer needs to be a member variable, not just in the scope of a method.
This means that
Timer clock = new Timer();
goes inside the class, but outside of any methods.
Sorry, I just assumed it was, but I see now it wasn't.
I tried that:
The name 'clock' does not exist in the current context
System.Timers.Timer t = new System.Timers.Timer();
t.AutoReset = false;
t.Elapsed += new System.Timers.ElapsedEventHandler(sc_TikTak);
t.Interval = 1000;
t.Start();
I think it is the best way to do it :)
private void start(object sender, EventArgs e) {
clock.Stop();
Make a timer go once
El locolito
Your timer needs to be a member variable, not just in the scope of a method.
This means that
Timer clock = new Timer();
goes inside the class, but outside of any methods.
Sorry, I just assumed it was, but I see now it wasn't.
Dan Hadfield
I tried that:
The name 'clock' does not exist in the current context
Jon Russell
System.Timers.Timer t = new System.Timers.Timer();
t.AutoReset = false;
t.Elapsed += new System.Timers.ElapsedEventHandler(sc_TikTak);
t.Interval = 1000;
t.Start();
I think it is the best way to do it :)
Jeff B.
private void start(object sender, EventArgs e) {
clock.Stop();
denszon