Mercurial > pub > ImplabNet
comparison Implab/Disposable.cs @ 40:fe33f4e02ad5
improved tracing
added text listeners (file,console)
author | cin |
---|---|
date | Tue, 15 Apr 2014 17:52:09 +0400 |
parents | |
children | d9d794b61bb9 |
comparison
equal
deleted
inserted
replaced
39:6498078ae368 | 40:fe33f4e02ad5 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Diagnostics; | |
4 using System.Linq; | |
5 using System.Web; | |
6 | |
7 namespace Implab { | |
8 public class Disposable : IDisposable { | |
9 | |
10 bool m_disposed; | |
11 | |
12 public event EventHandler Disposed; | |
13 | |
14 public bool IsDisposed { | |
15 get { return m_disposed; } | |
16 } | |
17 | |
18 protected void AssertNotDisposed() { | |
19 if (m_disposed) | |
20 throw new ObjectDisposedException(this.ToString()); | |
21 } | |
22 | |
23 protected virtual void Dispose(bool disposing) { | |
24 if (disposing && !m_disposed) { | |
25 m_disposed = true; | |
26 | |
27 EventHandler temp = Disposed; | |
28 if (temp != null) | |
29 temp(this,EventArgs.Empty); | |
30 } | |
31 } | |
32 public void Dispose() { | |
33 Dispose(true); | |
34 GC.SuppressFinalize(this); | |
35 } | |
36 | |
37 protected virtual void ReportObjectLeaks() { | |
38 Trace.TraceWarning("The object is marked as disposable but isn't disposed properly: {0}", this); | |
39 } | |
40 | |
41 ~Disposable() { | |
42 Dispose(false); | |
43 ReportObjectLeaks(); | |
44 } | |
45 } | |
46 } |