using IntelligentControlForsx.MyControls; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace IntelligentControlForsx.Code { public class WpfMessage { static List Wpfs = new List(); static object o = new object(); public static void AddWpf(WpfWindturbine wpf) { lock (o) Wpfs.Add(wpf); } public static void DeleteWpf(WpfWindturbine wpf) { lock (o) Wpfs.Remove(wpf); } public static void SetWpfTest() { Thread T = new Thread(SetWpfText); T.IsBackground = true; T.Start(); } public static void SetWpfText() { while (true) { Console.WriteLine(Wpfs.Count); lock (o) foreach (WpfWindturbine l in Wpfs) { if (CommunalTarget.UdpDoubleMemory.ContainsKey(l.TestPointId)) { Action action1 = () => { l.State = (int)CommunalTarget.UdpDoubleMemory[l.TestPointId]; }; l.Dispatcher.BeginInvoke(action1); } } } } } }