updates the BackgroundTaskRunnerAwaiter so that it exits if the runner is not running when it is ctor'd, adds diags.

This commit is contained in:
Shannon
2015-04-09 17:59:34 +10:00
parent c525be3e44
commit c78b371965
2 changed files with 18 additions and 3 deletions

View File

@@ -260,6 +260,8 @@ namespace Umbraco.Web.Scheduling
{
if (token.IsCancellationRequested || _tasks.Count == 0)
{
LogHelper.Debug<BackgroundTaskRunner<T>>("_isRunning = false");
_isRunning = false; // done
if (_options.PreserveRunningTask == false)
_runningTask = null;

View File

@@ -1,6 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Umbraco.Core.Logging;
namespace Umbraco.Web.Scheduling
{
@@ -27,16 +28,23 @@ namespace Umbraco.Web.Scheduling
_tcs = new TaskCompletionSource<int>();
_awaiter = _tcs.Task.GetAwaiter();
if (_runner.IsRunning)
{
_runner.Completed += (s, e) => _tcs.SetResult(0);
_runner.Completed += (s, e) =>
{
LogHelper.Debug<BackgroundTaskRunnerAwaiter<T>>("Setting result");
_tcs.SetResult(0);
};
}
else
{
//not running, just set the result
_tcs.SetResult(0);
}
_awaiter = _tcs.Task.GetAwaiter();
}
public BackgroundTaskRunnerAwaiter<T> GetAwaiter()
@@ -49,7 +57,12 @@ namespace Umbraco.Web.Scheduling
/// </summary>
public bool IsCompleted
{
get { return _runner.IsRunning == false; }
get
{
LogHelper.Debug<BackgroundTaskRunnerAwaiter<T>>("IsCompleted :: " + _tcs.Task.IsCompleted + ", " + (_runner.IsRunning == false));
//Need to check if the task is completed because it might already be done on the ctor and the runner never runs
return _tcs.Task.IsCompleted || _runner.IsRunning == false;
}
}
public void OnCompleted(Action continuation)