0

I use a timer initialized like this:

timer = new System.Windows.Forms.Timer
{
    Interval = monitorConfig.Interval
};

timer.Tick += Timer_Tick;

In Timer_Tick event, after a certain condition I stop ther timer with

timer.Stop();

I do some stuff then i try to restart the timer after a delay like this:

var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;

Task.Delay(timerDelay).ContinueWith((t) =>
{
    logger.Info("Starting Timer");
    timer.Start();
}, cancellationToken);

But the timer does not restart I must be missing something Thank you for your help

  • From looking over the internet it seems like you have 2 options: (1) Stop() and then Start() (2) AutoReset. Check out these links: (1) https://stackoverflow.com/questions/1042312/how-to-reset-a-timer-in-c (2) https://www.delftstack.com/howto/csharp/reset-timer-in-csharp/ – MC LinkTimeError Nov 15 '22 at 10:09
  • Hello, I try to restart the timer after a delay – Sadri Lassoued Nov 15 '22 at 10:17

1 Answers1

1

Fixed by using

System.Timers.Timer