Beispiel #1
0
 protected void RemvoeExpiredTasks()
 {
     while (CurrentTasks.Count > 0 && CurrentTasks.Peek() <= DateTime.Now)
     {
         CurrentTasks.Dequeue();
     }
 }
Beispiel #2
0
 private void ProcessIndividualTask()
 {
     if (CurrentTasks.Count > 0)
     {
         TaskItem currenttask = CurrentTasks.Dequeue();
         currenttask.CurrentTask.ContinueWith(x => ProcessIndividualTask());
         currenttask.CurrentTask.Start();
     }
     else
     {
         TaskQueueRunning = false;
     }
 }
Beispiel #3
0
        public void StartTask()
        {
            bool finished = false;

            while (!finished)
            {
                while (NumberOfOutstandingTasks >= SimultaneiousTasksLimit)
                {
                    System.Threading.Thread.Sleep(100);
                }

                lock (lockObject)
                {
                    if (NumberOfOutstandingTasks >= SimultaneiousTasksLimit)
                    {
                        // Another thread added a task to the queue before we could get the lock.
                        continue;
                    }

                    RemvoeExpiredTasks();
                    if (CurrentTasks.Count == WindowLimit)
                    {
                        TimeSpan waitTime = CurrentTasks.Dequeue() - DateTime.Now;
                        if (waitTime.TotalMilliseconds > 0)
                        {
                            Throttled?.Invoke(this, new ThottledEventArgs(waitTime));
                            System.Threading.Thread.Sleep(waitTime);
                        }
                    }

                    System.Threading.Interlocked.Increment(ref _numberOfOutstandingTasks);
                    CurrentTasks.Enqueue(DateTime.Now + WindowSize);
                    finished = true;
                }
            }
        }