//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.GameLogic;
///
/// Base class for classes which want to implement .
///
public class AsyncDisposable : Disposable, IAsyncDisposable
{
private bool _isDisposing;
///
/// Gets a value indicating whether this instance is disposing.
///
///
/// true if this instance is disposing; otherwise, false.
///
public new bool IsDisposing
{
get => this._isDisposing || base.IsDisposing;
private set => this._isDisposing = value;
}
///
public async ValueTask DisposeAsync()
{
if (!this.IsDisposed && !this.IsDisposing)
{
this.IsDisposing = true;
try
{
await this.DisposeAsyncCore().ConfigureAwait(false);
this.Dispose(true);
GC.SuppressFinalize(this);
}
finally
{
this.IsDisposing = false;
}
}
}
///
/// Performs application-defined tasks associated with freeing, releasing, or
/// resetting unmanaged resources asynchronously.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "VSTHRD200:Use \"Async\" suffix for async methods", Justification = "This naming is suggested by microsoft itself.")]
protected virtual ValueTask DisposeAsyncCore()
{
return ValueTask.CompletedTask;
}
}