| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | 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<TimerViewModelBase> _lstAll = new List<TimerViewModelBase>();        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);	}}
 |