WpfMessage.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using IntelligentControlForsx.MyControls;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace IntelligentControlForsx.Code
  9. {
  10. public class WpfMessage
  11. {
  12. static List<WpfWindturbine> Wpfs = new List<WpfWindturbine>();
  13. static object o = new object();
  14. public static void AddWpf(WpfWindturbine wpf)
  15. {
  16. lock (o)
  17. Wpfs.Add(wpf);
  18. }
  19. public static void DeleteWpf(WpfWindturbine wpf)
  20. {
  21. lock (o)
  22. Wpfs.Remove(wpf);
  23. }
  24. public static void SetWpfTest()
  25. {
  26. Thread T = new Thread(SetWpfText);
  27. T.IsBackground = true;
  28. T.Start();
  29. }
  30. public static void SetWpfText()
  31. {
  32. while (true)
  33. {
  34. Console.WriteLine(Wpfs.Count);
  35. lock (o)
  36. foreach (WpfWindturbine l in Wpfs)
  37. {
  38. if (CommunalTarget.UdpDoubleMemory.ContainsKey(l.TestPointId))
  39. {
  40. Action action1 = () =>
  41. {
  42. l.State = (int)CommunalTarget.UdpDoubleMemory[l.TestPointId];
  43. };
  44. l.Dispatcher.BeginInvoke(action1);
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }