public static void TestAsyncMethod() { Console.WriteLine($"Async Method Test. Time: {DateTime.UtcNow:o}"); TimerDemo t = new TimerDemo(); Timer serviceHeartbeatTimer = new Timer(t.TestAsync); // The two input is the duration between start time and now, the period. serviceHeartbeatTimer.Change(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1)); }
public static void ZeroSecondTrigger() { int minutes = 2; Console.WriteLine($"Async Method Test. Time: {DateTime.UtcNow:o}"); TimerDemo t = new TimerDemo(); Timer serviceHeartbeatTimer = new Timer(t.ZeroSecondTrigger); // Trigger the function in the beginning of every few mins serviceHeartbeatTimer.Change(TimeSpan.FromMilliseconds((minutes - DateTime.Now.Minute % minutes) * 60 * 1000 - DateTime.Now.Second * 1000 - DateTime.UtcNow.Millisecond), TimeSpan.FromMinutes(minutes)); }