public void SingleShotTimer_Elapsed_CanRestartTimer() { int actionCount = 0; using (ActionThread thread = new ActionThread()) { thread.Start(); Timer timer = null; thread.DoSynchronously(() => { timer = new Timer(); timer.Elapsed += () => { if (actionCount == 0) { timer.Restart(); } ++actionCount; }; timer.AutoReset = false; timer.Interval = TimeSpan.FromMilliseconds(0); timer.Enabled = true; }); Thread.Sleep(10); thread.DoSynchronously(() => timer.Dispose()); } Assert.AreEqual(2, actionCount, "Timer did not honor Restart when called from Elapsed"); }
public void Timer_AfterRestart_IsEnabled() { bool enabled = false; using (ActionThread thread = new ActionThread()) { thread.Start(); thread.DoSynchronously(() => { using (Timer timer = new Timer()) { timer.SetPeriodic(TimeSpan.FromMilliseconds(50)); timer.Restart(); enabled = timer.Enabled; } }); } Assert.IsTrue(enabled, "Timer.Enabled should be true"); }