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