/// <summary>Queues a task to the scheduler.</summary> /// <param name="task">The task to be queued.</param> protected override void QueueTask(Task task) { #if DEBUG if (logger.IsVerbose2) logger.Verbose2(myId + " QueueTask Task Id={0}", task.Id); #endif var atask = new ActivationTask(task, IsReactive); workerGroup.EnqueueTask(atask); }
/// <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(ActivationTask atask) { lock (lockable) { #if DEBUG if (log.IsVerbose2) log.Verbose2("EnqueueWorkItem {0} into {1} when TaskScheduler.Current={2}", atask.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.", atask.Task), ErrorCode.SchedulerNotEnqueuWorkWhenShutdown); atask.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(atask); 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}", atask.Task, thisSequenceNumber, SchedulingContext); #endif masterScheduler.RunQueue.Add(this); } }