| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Threading;using System.Threading;using OpenSEMI.Core.Msg;namespace OpenSEMI.ClientBase.UI{    public class UIHandler : IHandler    {        public UIHandler()        {            this.acts = new Dictionary<string, Action>();            this.Looper = new MsgPool(500, Do);        }        public void Handle()        {            this.Looper.Run();        }        private void Do(MsgPool looper)        {            lock(lockObj)            {                if (Application.Current == null || Application.Current.Dispatcher == null)                    return;                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate                {                    foreach (KeyValuePair<string, Action> kv in this.acts)                    {                        kv.Value();                    }                });            }        }        public void Register(string key, Action act)        {            lock(lockObj)            {                if (!this.acts.ContainsKey(key))                {                    this.acts.Add(key, act);                }            }        }        public void UnRegister(string key)        {            lock(lockObj)            {                if (this.acts.ContainsKey(key))                    this.acts.Remove(key);            }        }        public MsgPool Looper { get; private set; }        private Dictionary<string, Action> acts;        private static object lockObj = new object();    }}
 |