Example #1
0
 public bool CheckIfTaskRunning(IExecutableWorkItem item)
 {
     for (int i = 0; i < _allWorkItemQueues.Length; i++)
     {
         if (_allWorkItemQueues[i].AllItems.Count > 0)
         {
             if (_allWorkItemQueues[i].IsInList(item))
                 return true;
         }
     }
     return false;
 }
Example #2
0
        private int FindAppropriateQueue(IExecutableWorkItem workItemToExecute)
        {
            var ts = workItemToExecute.ExecutionTime.Subtract(CurrentDateTime);

            if (ts.TotalMilliseconds > _largeDelayQueueCutoffMs)
            {
                return(_totalThreads - 1);
            }
            if (ts.TotalMilliseconds > _moderateDelayQueueCutoffMs)
            {
                return(_totalThreads - 2);
            }
            return(Interlocked.Increment(ref _counter) % (_totalThreads - 2));
        }
Example #3
0
 /// <summary>
 /// Schedules a work item to execute at a specific time
 /// </summary>
 /// <param name="eventToExecute"></param>
 public void ScheduleEventToExecute(IExecutableWorkItem workItemToExecute)
 {
     int queueNum = FindAppropriateQueue(workItemToExecute);
     _allWorkItemQueues[queueNum].Enqueue(workItemToExecute);
     Interlocked.Increment(ref _workItemCount);
 }
Example #4
0
 /// <summary>
 /// Determines the appropriate queue in which to place the work item, based on its
 /// scheduled execution time
 /// </summary>
 /// <param name="eventToExecute"></param>
 /// <returns></returns>
 private int FindAppropriateQueue(IExecutableWorkItem workItemToExecute)
 {
     TimeSpan ts = workItemToExecute.ExecutionTime.Subtract(CurrentDateTime);
     return Interlocked.Increment(ref counter) % (TotalThreads);
 }