diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs
index 61e1f63299..0f3bae87c8 100644
--- a/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs
+++ b/MediaBrowser.Common.Implementations/ScheduledTasks/TaskManager.cs
@@ -106,7 +106,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// The task.
private void QueueScheduledTask(IScheduledTaskWorker task)
{
- var type = task.GetType();
+ var type = task.ScheduledTask.GetType();
lock (_taskQueue)
{
@@ -173,14 +173,46 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
return ((ScheduledTaskWorker)task).Execute();
}
+ ///
+ /// Called when [task executing].
+ ///
+ /// The task.
internal void OnTaskExecuting(IScheduledTask task)
{
EventHelper.QueueEventIfNotNull(TaskExecuting, task, EventArgs.Empty, Logger);
}
+ ///
+ /// Called when [task completed].
+ ///
+ /// The task.
+ /// The result.
internal void OnTaskCompleted(IScheduledTask task, TaskResult result)
{
EventHelper.QueueEventIfNotNull(TaskExecuting, task, new GenericEventArgs { Argument = result }, Logger);
+ ExecuteQueuedTasks();
+ }
+
+ ///
+ /// Executes the queued tasks.
+ ///
+ private void ExecuteQueuedTasks()
+ {
+ // Execute queued tasks
+ lock (_taskQueue)
+ {
+ foreach (var type in _taskQueue.ToList())
+ {
+ var scheduledTask = ScheduledTasks.First(t => t.ScheduledTask.GetType() == type);
+
+ if (scheduledTask.State == TaskState.Idle)
+ {
+ ((ScheduledTaskWorker)scheduledTask).Execute();
+
+ _taskQueue.Remove(type);
+ }
+ }
+ }
}
}
}