-3

I am working on a windows application where I start a timer .Everything is working but my reset of timer is working for me . It giving me error and timer does not reset

Coding is

 t = new System.Timers.Timer(); t.Interval = 1000; t.Elapsed += OnTimeEvent; t.Start(); 

Reset Button Code

 private void btnrest_Click(object sender, EventArgs e) { t.Dispose(); t = new System.Timers.Timer(); lbltime.Text = "00.00.00"; } 

But it is not working any help

6
  • Shouldn't you also set Interval and Elapsed in the reset button click handler? Commented Jul 24, 2020 at 10:15
  • Yes i did but not working ! Commented Jul 24, 2020 at 10:15
  • 2
    Doesn't work is not a helpful problem description! - It giving me error Then please do show that error!!! Commented Jul 24, 2020 at 10:22
  • Yes i try it but not working? Commented Jul 24, 2020 at 10:24
  • 1
    Does this answer your question? How to reset a timer in C#? Commented Jul 24, 2020 at 10:26

2 Answers 2

1

You could use something like this :

private void btnrest_Click(object sender, EventArgs e) { t.Stop(); t.Start(); } 
Sign up to request clarification or add additional context in comments.

Comments

0

Under reset click

t.Enabled = false; t = new System.Timers.Timer(); t.Interval = 1000; t.Elapsed += OnTimeEvent; t.Start(); // by default on start Enabled = true 

2 Comments

Adding these code start timer! nothing do anything .
Can you elaborate it more. The above code stops the timer and starts with new elapsed event on reset button. Is that what you expecting?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.