public static void ConsumeAll(int produced, IBlockingQueue<object> queue, int volume) { int[] consumed = { 0 }; while (consumed[0] < volume) { try { Thread.Sleep(10); var item = queue.Dequeue(); Assert.IsNotNull(item); Interlocked.Increment(ref consumed[0]); } catch (Exception ex) { Assert.Fail(ex.Message); } } while (consumed[0] < produced) { Assert.GreaterOrEqual(produced, consumed[0], "More messages reported consumed than produced"); } Assert.AreEqual(produced, consumed[0], "Consumers reported complete before a count mismatch"); }
void Run() { ResultExecutionTask task; while ((task = _taskQueue.Dequeue()) != null) { task.Execute(); } }
void ProcessTaskQueue() { IronConsoleTask task; while ((task = _queue.Dequeue()) != null) { task.Execute(); } }
volatile bool _isStartDelay = false;//是否开启延迟任务线程,有插入延迟任务时就 自动开启,默认不开启 private void StartRunTask() { Task.Factory.StartNew(async() => { while (_isStart) { try { var action = _taskQueue.Dequeue(); await action.Run(action.state); } catch (Exception ex) { await handlerException(ex); } } }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default); }