using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Threading; using System.ComponentModel; using System.Threading.Tasks; using System.Reflection; using Aitex.Core.Util; using System.Windows; using Aitex.Core.RT.Log; namespace Aitex.Core.UI.MVVM { public abstract class TimerViewModelBase : ViewModelBase, ITimerViewModelBase { PeriodicJob _timer; //static List _lstAll = new List(); protected bool _isStart = false; public static void StopAll() { //foreach (TimerViewModelBase vm in _lstAll) // vm.Stop(); } public TimerViewModelBase(string name) { _timer = new PeriodicJob(1000, this.OnTimer, "UIUpdaterThread - " + name, false, true); //_lstAll.Add(this); } // protected virtual bool OnTimer() { try { Poll(); } catch (Exception ex) { LOG.WriteExeption(ex); } return true; } public void Start() { _timer.Start(); _isStart = true; } public void Stop() { _timer.Stop(); _isStart = false; } public void Dispose() { Stop(); } protected abstract void Poll(); public virtual void UpdateData() { } public virtual void EnableTimer(bool enable) { if (enable) { _timer.Start(); _isStart = true; } else { _timer.Pause(); _isStart = false; } } } public interface ITimerViewModelBase { void EnableTimer(bool enable); } }