public void Add(IWorkItem workItem) { workItem.TimeQueued = DateTime.UtcNow; try { #if PRIORITIZE_SYSTEM_TASKS if (workItem.IsSystemPriority) { #if TRACK_DETAILED_STATS if (StatisticsCollector.CollectShedulerQueuesStats) { systemQueueTracking.OnEnQueueRequest(1, systemQueue.Count); } #endif systemQueue.Add(workItem); } else { #if TRACK_DETAILED_STATS if (StatisticsCollector.CollectShedulerQueuesStats) { mainQueueTracking.OnEnQueueRequest(1, mainQueue.Count); } #endif mainQueue.Add(workItem); } #else #if TRACK_DETAILED_STATS if (StatisticsCollector.CollectQueueStats) { mainQueueTracking.OnEnQueueRequest(1, mainQueue.Count); } #endif mainQueue.Add(task); #endif #if TRACK_DETAILED_STATS if (StatisticsCollector.CollectGlobalShedulerStats) { SchedulerStatisticsGroup.OnWorkItemEnqueue(); } #endif } catch (InvalidOperationException) { // Queue has been stopped; ignore the exception } }
public void OnEnQueueRequest(WorkItem workItem) { if (this.statisticsLevel.CollectDetailedQueueStatistics()) { queueTracking.OnEnQueueRequest(1, queueLength: 0, itemInQueue: workItem.ExecutionTime); } }
public void OnEnQueueRequest(WorkItem workItem) { if (ExecutorOptions.CollectDetailedQueueStatistics) { queueTracking.OnEnQueueRequest(1, queueLength: 0, itemInQueue: workItem.ExecutionTime); } }
/// <summary> /// Adds a task to this activation. /// If we're adding it to the run list and we used to be waiting, now we're runnable. /// </summary> /// <param name="task">The work item to add.</param> public void EnqueueTask(Task task) { lock (lockable) { #if DEBUG if (log.IsVerbose2) { log.Verbose2("EnqueueWorkItem {0} into {1} when TaskScheduler.Current={2}", task, SchedulingContext, TaskScheduler.Current); } #endif if (state == WorkGroupStatus.Shutdown) { ReportWorkGroupProblem( String.Format("Enqueuing task {0} to a stopped work item group. Going to ignore and not execute it. " + "The likely reason is that the task is not being 'awaited' properly.", task), ErrorCode.SchedulerNotEnqueuWorkWhenShutdown); task.Ignore(); // Ignore this Task, so in case it is faulted it will not cause UnobservedException. return; } long thisSequenceNumber = totalItemsEnQueued++; int count = WorkItemCount; #if TRACK_DETAILED_STATS if (StatisticsCollector.CollectShedulerQueuesStats) { queueTracking.OnEnQueueRequest(1, count); } if (StatisticsCollector.CollectGlobalShedulerStats) { SchedulerStatisticsGroup.OnWorkItemEnqueue(); } #endif workItems.Enqueue(task); int maxPendingItemsLimit = masterScheduler.MaxPendingItemsLimit.SoftLimitThreshold; if (maxPendingItemsLimit > 0 && count > maxPendingItemsLimit) { log.Warn(ErrorCode.SchedulerTooManyPendingItems, String.Format("{0} pending work items for group {1}, exceeding the warning threshold of {2}", count, Name, maxPendingItemsLimit)); } if (state != WorkGroupStatus.Waiting) { return; } state = WorkGroupStatus.Runnable; #if DEBUG if (log.IsVerbose3) { log.Verbose3("Add to RunQueue {0}, #{1}, onto {2}", task, thisSequenceNumber, SchedulingContext); } #endif masterScheduler.RunQueue.Add(this); } }
internal void QueueIncomingMessage(Message msg) { #if TRACK_DETAILED_STATS if (StatisticsCollector.CollectQueueStats) { queueTracking.OnEnQueueRequest(1, PendingInboundMessages.Count, msg); } #endif PendingInboundMessages.Add(msg); }