Updates BackgroundTaskRunner to ensure canceled or skipped tasks are disposed, updated tests to reflect

This commit is contained in:
Shannon
2015-02-04 15:12:37 +11:00
parent 912b01c9aa
commit bc068b201d
4 changed files with 43 additions and 29 deletions

View File

@@ -8,26 +8,6 @@ using Umbraco.Core.Logging;
namespace Umbraco.Web.Scheduling
{
internal class BackgroundTaskRunnerOptions
{
public BackgroundTaskRunnerOptions()
{
DedicatedThread = false;
PersistentThread = false;
OnlyProcessLastItem = false;
}
public bool DedicatedThread { get; set; }
public bool PersistentThread { get; set; }
/// <summary>
/// If this is true, the task runner will skip over all items and only process the last/final
/// item registered
/// </summary>
public bool OnlyProcessLastItem { get; set; }
}
/// <summary>
/// This is used to create a background task runner which will stay alive in the background of and complete
/// any tasks that are queued. It is web aware and will ensure that it is shutdown correctly when the app domain
@@ -174,7 +154,8 @@ namespace Umbraco.Web.Scheduling
//skip if this is not the last
if (_options.OnlyProcessLastItem && _tasks.Count > 0)
{
//NOTE: don't raise canceled event, we're shutting down
//NOTE: don't raise canceled event, we're shutting down, just dispose
remainingTask.Dispose();
continue;
}
@@ -372,6 +353,9 @@ namespace Umbraco.Web.Scheduling
{
var handler = TaskCancelled;
if (handler != null) handler(this, e);
//dispose it
e.Task.Dispose();
}