private static void ClearIntoTaskQueue() { while (ComTaskQueue.Count > 0) { TaskContent nill = new TaskContent(); ComTaskQueue.TryDequeue(out nill); } ComTaskQueueKeys.Clear(); }
private static void AddIntoTaskQueue(int idx, string PortName, byte[] sBytes, int needRetry) { lock (ComTaskQueue) { string thisKey = PortName + AnyBytesToString(sBytes); if (ComTaskQueueKeys.ContainsKey(thisKey)) { return; } TaskContent neoTask = new TaskContent(); neoTask.idx = idx; neoTask.PortName = PortName; neoTask.sBytes = sBytes; neoTask.needRetry = needRetry; System.Diagnostics.Debug.WriteLine("elegated!" + ComTaskQueue.Count + "&" + thisKey); ComTaskQueueKeys[thisKey] = 1; ComTaskQueue.Enqueue(neoTask); } }
// disable once FunctionNeverReturns private static void ScanTaskQueue() { while (true) { Thread.Sleep(200); if (ComTaskQueue.Count > 0) { TaskContent next = new TaskContent(); lock (ComTaskQueue) { ComTaskQueue.TryDequeue(out next); } if (next.idx != -1) { ComTaskQueueKeys.Remove(next.PortName + AnyBytesToString(next.sBytes)); sendToMachine(next.idx, next.PortName, next.sBytes, next.needRetry); } } } }