DisposableObject - cleanup & use

This commit is contained in:
Stephan
2015-07-14 15:55:56 +02:00
parent a4dbc33b9a
commit 161f2eda86
3 changed files with 34 additions and 66 deletions

View File

@@ -1,13 +1,13 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Umbraco.Core;
namespace Umbraco.Web.Scheduling
{
internal abstract class LatchedBackgroundTaskBase : ILatchedBackgroundTask
internal abstract class LatchedBackgroundTaskBase : DisposableObject, ILatchedBackgroundTask
{
private readonly ManualResetEventSlim _latch;
private bool _disposed;
protected LatchedBackgroundTaskBase()
{
@@ -51,34 +51,13 @@ namespace Umbraco.Web.Scheduling
public abstract bool RunsOnShutdown { get; }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
// the task is going to be disposed again after execution,
// the task is going to be disposed after execution,
// unless it is latched again, thus indicating it wants to
// remain active
protected virtual void Dispose(bool disposing)
protected override void DisposeResources()
{
if (disposing == false) return;
// lock on _latch instead of creating a new object as _latch is
// private, non-null, readonly - so safe here
lock (_latch)
{
if (_disposed) return;
_disposed = true;
_latch.Dispose();
DisposeResources();
}
_latch.Dispose();
}
protected virtual void DisposeResources()
{ }
public bool Disposed { get { return _disposed; } }
}
}