##// END OF EJS Templates
Working on runnable component
Working on runnable component

File last commit:

r250:9f63dade3a40 v3
r250:9f63dade3a40 v3
Show More
Disposable.cs
62 lines | 2.4 KiB | text/x-csharp | CSharpLexer
cin
component model refactoring
r152 using Implab.Diagnostics;
using System;
cin
RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)...
r208 using System.Diagnostics.CodeAnalysis;
cin
component model refactoring
r152 using System.Threading;
namespace Implab.Components {
/// <summary>
/// Base class the objects which support disposing.
/// </summary>
public class Disposable : IDisposable {
cin
Minor code changes
r213
cin
component model refactoring
r152 public event EventHandler Disposed;
public bool IsDisposed {
cin
Working on runnable component
r250 get; private set;
cin
component model refactoring
r152 }
/// <summary>
/// Asserts the object is not disposed.
/// </summary>
/// <exception cref="ObjectDisposedException">The object is disposed</exception>
/// <remarks>
protected void AssertNotDisposed() {
cin
Working on runnable component
r250 if (IsDisposed)
cin
component model refactoring
r152 throw new ObjectDisposedException(ToString());
}
/// <summary>
/// Вызывает событие <see cref="Disposed"/>
/// </summary>
/// <param name="disposing">Признак того, что нужно освободить ресурсы, иначе данный метод
/// вызван сборщиком мусора и нужно освобождать ТОЛЬКО неуправляемые ресурсы ТОЛЬКО этого
/// объекта.</param>
/// <remarks>
/// Данный метод вызывается гарантированно один раз даже при одновременном вызове <see cref="Dispose()"/>
/// из нескольких потоков.
/// </remarks>
protected virtual void Dispose(bool disposing) {
cin
Minor code changes
r213 if (disposing)
Disposed.DispatchEvent(this, EventArgs.Empty);
cin
component model refactoring
r152 }
cin
RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)...
r208 [SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Dipose(bool) and GC.SuppessFinalize are called")]
cin
component model refactoring
r152 public void Dispose() {
cin
Working on runnable component
r250 if(!IsDisposed) {
IsDisposed = true;
cin
component model refactoring
r152 Dispose(true);
GC.SuppressFinalize(this);
}
}
/// <summary>
/// Записывает сообщение об утечке объекта.
/// </summary>
protected virtual void ReportObjectLeaks() {
TraceLog.TraceWarning("The object is marked as disposable but isn't disposed properly: {0}", this);
}
~Disposable() {
Dispose(false);
ReportObjectLeaks();
}
}
}