public void BeginSendInfo() { Task.Run(async() => { while (true) { for (int i = 0; i < LEDs.Count(); i++) { await Task.Delay(500); if (LEDs[i] != null) { if (MQs.TryGetValue(LEDs[i].LEDIP, out Queue <string> mq)) { if (mq.Count > 0) { string msg = mq.Dequeue(); int n = LEDs[i].SendLedInfo(msg); if (i != 0) { var option = Options.FirstOrDefault(t => t.IP == LEDs[i].LEDIP); if (option != null) { LEDs[i] = new LED(option.IP, option.Port, option.Timesec); LEDs[i].SendLedInfo(msg); } } } } } } } }); }
public void Push(string key, string msg) { if (string.IsNullOrWhiteSpace(key)) { return; } if (MQs.TryGetValue(key, out Queue <string> mq)) { mq.Enqueue(msg); } else { Queue <string> q = new Queue <string>(); q.Enqueue(msg); MQs.Add(key, q); } }