using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace IntelligentControlForsx.Code { public class PanelMessage { readonly static ConcurrentDictionary Panels = new ConcurrentDictionary(); static Thread T; public static void AddPanel(TableLayoutPanel panels) { Panels.TryAdd(panels.Name, panels); } public static void DeletePanel(TableLayoutPanel panels) { Panels.TryRemove(panels.Name, out panels); } public static void SetBackColorTest() { T = new Thread(SetPanelText); T.IsBackground = true; T.Start(); } public static void SetPanelText() { while (true) { Console.WriteLine(Panels.Count); foreach (TableLayoutPanel l in Panels.Values) { if (l.Tag == null) { Console.WriteLine("1"); } if (CommunalTarget.UdpDoubleMemory.ContainsKey(((MyKeyValue)l.Tag).Key)) { Action action1 = () => { GetBackColor(l, (int)CommunalTarget.UdpDoubleMemory[((MyKeyValue)l.Tag).Key]); ((MyKeyValue)l.Tag).Value = (int)CommunalTarget.UdpDoubleMemory[((MyKeyValue)l.Tag).Key]; }; if (l.IsHandleCreated) { try { l.Invoke(action1); } catch (Exception e) { Console.WriteLine(e.Message); break; } } } } Thread.Sleep(1000); } } private static void GetBackColor(TableLayoutPanel panel,int Color) { switch (Color) { case 0: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(36)))), ((int)(((byte)(161)))), ((int)(((byte)(58))))); break; } case 1: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(36)))), ((int)(((byte)(161)))), ((int)(((byte)(58))))); break; } case 2: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(165)))), ((int)(((byte)(219))))); break; } case 3: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(165)))), ((int)(((byte)(219))))); break; } case 4: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(177)))), ((int)(((byte)(14)))), ((int)(((byte)(126))))); break; } case 5: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(177)))), ((int)(((byte)(14)))), ((int)(((byte)(126))))); break; } case 6: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(32)))), ((int)(((byte)(32))))); break; } case 7: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(32)))), ((int)(((byte)(32))))); break; } case 8: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(120)))), ((int)(((byte)(0))))); break; } case 9: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(120)))), ((int)(((byte)(0))))); break; } case 10: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30))))); break; } case 11: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30))))); break; } case 12: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(146)))), ((int)(((byte)(156)))), ((int)(((byte)(163))))); break; } default: { panel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(64))))); break; } } } } }