示例#1
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources
 /// </summary>
 public void Dispose()
 {
     lock (disposalAccess)
         if (!IsDisposed)
         {
             var e = new DisposalNotificationEventArgs(false);
             OnDisposing(e);
             Dispose(true);
             IsDisposed = true;
             OnDisposed(e);
             Disposing = null;
             Disposed  = null;
             GC.SuppressFinalize(this);
         }
 }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources
        /// </summary>
        /// <param name="cancellationToken">A token that can be used to attempt to cancel disposal</param>
        /// <exception cref="OperationCanceledException">Disposal was interrupted by a cancellation request</exception>
        public async Task DisposeAsync(CancellationToken cancellationToken = default)
        {
            using (await disposalAccess.LockAsync(cancellationToken).ConfigureAwait(false))
                if (!isDisposed)
                {
                    var e = new DisposalNotificationEventArgs(false);
                    OnDisposing(e);
                    await DisposeAsync(true, cancellationToken).ConfigureAwait(false);

                    IsDisposed = true;
                    OnDisposed(e);
                    Disposing = null;
                    Disposed  = null;
                    GC.SuppressFinalize(this);
                }
        }
示例#3
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources
 /// </summary>
 public void Dispose()
 {
     lock (disposalAccess)
         if (!IsDisposed)
         {
             var e = new DisposalNotificationEventArgs(false);
             OnDisposing(e);
             if (IsDisposed = Dispose(true))
             {
                 OnDisposed(e);
                 Disposing          = null;
                 DisposalOverridden = null;
                 Disposed           = null;
                 GC.SuppressFinalize(this);
             }
             else
             {
                 OnDisposalOverridden(e);
             }
         }
 }
示例#4
0
 /// <summary>
 /// Raises the <see cref="Disposing"/> event with the specified arguments
 /// </summary>
 /// <param name="e">The event arguments</param>
 protected virtual void OnDisposing(DisposalNotificationEventArgs e) => Disposing?.Invoke(this, e);
示例#5
0
 /// <summary>
 /// Raises the <see cref="DisposalOverridden"/> event with the specified arguments
 /// </summary>
 /// <param name="e">The event arguments</param>
 protected virtual void OnDisposalOverridden(DisposalNotificationEventArgs e) => DisposalOverridden?.Invoke(this, e);