public void TestMethod1() { m_task = new ScheduledTask(ThreadingMode.DedicatedBackground,ThreadPriority.Highest); m_task.Running += task_Running; m_task.Start(10); Thread.Sleep(1000); m_task.Dispose(); System.Console.WriteLine("Disposed"); }
protected override void Dispose(bool disposing) { if (!m_disposed) { m_disposed = true; m_timer?.Dispose(); m_timer = null; } base.Dispose(disposing); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { // Causes the status to be generated one last time before clearing everything m_reportStatus.Dispose(); lock (m_syncRoot) { m_disposed = true; foreach (SharedTimerInstance instance in m_schedulesByInterval.Values) { instance.Dispose(); } m_schedulesByInterval.Clear(); } m_log.Publish(MessageLevel.Warning, "Timer Disposed"); }
/// <summary> /// Stops the timer. The call that stops the timer /// will pause until the event is stopped. Any subsequent /// calls will return immediately. /// </summary> public void Stop() { lock (m_syncRoot) { if (!m_isRunning) { return; } if (m_stopping) { return; } m_stopping = true; } m_timer.Dispose(); lock (m_syncRoot) { m_timer = null; m_stopping = false; m_isRunning = false; } Log.Publish(MessageLevel.Info, "EventTimer Started"); }