Ejemplo n.º 1
0
        /// <summary>
        /// Enqueues the specified work item.
        /// </summary>
        /// <param name="backgroundTask">The work item.</param>
        public void Enqueue(IBackgroundTask backgroundTask)
        {
            var task = (BackgroundTask)backgroundTask;

            lock (syncroot)
            {
                if (backgroundTask.MaxQueuedInstances == GetQueuedInstances(backgroundTask.GetType(), (BackgroundTask)backgroundTask))
                {
                    Trace.WriteLine(String.Format("Task {0} has allready reached maximum allowed instances in the queue, ignoring enqueue...", backgroundTask.GetType()));

                    task.OnFinished();
                    return;
                }

                // Else
                Tasks.Add(task);
            }

            // Signal the processing pool to start (if it wasn't allready running)
            ProcessingPool.Process();
        }
Ejemplo n.º 2
0
 public TaskQueue()
 {
     Tasks          = new List <IBackgroundTask>();
     ProcessingPool = new ProcessingPool(this);
 }