using System;
namespace mRemoteNG.Tools
{
///
/// Represents an action that will be executed when the
/// method is called. Useful for creating Using blocks around logical start/end
/// actions.
///
public class DisposableAction : IDisposable
{
private bool _isDisposed;
private readonly Action _disposeAction;
///
///
///
///
/// An that should be performed immediately
/// when this object is initialized. It should return quickly.
///
///
/// An to be executed when this object is disposed.
///
public DisposableAction(Action initializeAction, Action disposeAction)
{
initializeAction();
_disposeAction = disposeAction;
}
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (!disposing || _isDisposed)
return;
_isDisposed = true;
_disposeAction();
}
}
}