Search code examples
c#multithreadingtimer

Timer to restart function when completed


I'm currently stuck on a problem with a timer.

I've got a function that is started by a timer every x seconds. Now the function execution can sometimes take longer under different conditions. So I want the timer to rerun only when it has completed the function. How can I achieve this?


Solution

  • Right before it exits, your function could trigger an event. The event will be caught by another function, which will start the timer.