* Update gitignore * Move csproj * Update project references * Update solutions * Update build scripts * Tests used to share editorconfig with projects in src * Fix broken tests. * Stop copying around .editorconfig merged root one with linting * csharp_style_expression_bodied -> suggestion * Move StyleCop rulesets to matching directories and update shared build properties * Remove legacy build files, update NuGet.cofig and solution files * Restore myget source * Clean up .gitignore * Update .gitignore * Move new test classes to tests after merge * Gitignore + nuget config * Move new test Co-authored-by: Ronald Barendse <ronald@barend.se>
62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Umbraco.Cms.Core;
|
|
|
|
namespace Umbraco.Web.Scheduling
|
|
{
|
|
public abstract class LatchedBackgroundTaskBase : DisposableObjectSlim, ILatchedBackgroundTask
|
|
{
|
|
private TaskCompletionSource<bool> _latch;
|
|
|
|
protected LatchedBackgroundTaskBase()
|
|
{
|
|
_latch = new TaskCompletionSource<bool>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Implements IBackgroundTask.Run().
|
|
/// </summary>
|
|
public virtual void Run()
|
|
{
|
|
throw new NotSupportedException("This task cannot run synchronously.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Implements IBackgroundTask.RunAsync().
|
|
/// </summary>
|
|
public virtual Task RunAsync(CancellationToken token)
|
|
{
|
|
throw new NotSupportedException("This task cannot run asynchronously.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indicates whether the background task can run asynchronously.
|
|
/// </summary>
|
|
public abstract bool IsAsync { get; }
|
|
|
|
public Task Latch => _latch.Task;
|
|
|
|
public bool IsLatched => _latch.Task.IsCompleted == false;
|
|
|
|
protected void Release()
|
|
{
|
|
_latch.SetResult(true);
|
|
}
|
|
|
|
protected void Reset()
|
|
{
|
|
_latch = new TaskCompletionSource<bool>();
|
|
}
|
|
|
|
public virtual bool RunsOnShutdown => false;
|
|
|
|
// the task is going to be disposed after execution,
|
|
// unless it is latched again, thus indicating it wants to
|
|
// remain active
|
|
|
|
protected override void DisposeResources()
|
|
{ }
|
|
}
|
|
}
|