示例#1
0
        protected void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    try
                    {
                        DisposableTracker.UnregisterInstance(this);                         // Only unregister if we were explicitly disposed. Otherwise we want to continue tracking so we can report on the failure to dispose correctly even if the object is finalised.
                    }
                    catch
                    {
                                                #if DEBUG
                        throw;
                                                #endif
                    }                     // Errors unregistering should be very rare, but in any case, make sure the dispose actually happens to prevent resources leaking.

                    DisposeManagedResources();
                }
            }
            finally
            {
                // Always attempt to dispose unmanaged resources, even in the event of an
                // exception disposing the managed ones. If an unexpected error occurred, then
                // it is highly likely to occur again (or worse, a different error from the partial
                // disposed state) if another dispose call is attempted. Of course most code should
                // not dispose objects more than once, so it's most likely we'll never get called again
                // anyway. In either case, the unmanaged resources woud be leaked if this is not called
                // from a finally block. Additionally, code in a finally block will also execute
                // if a thread abort occurs on the executing thread.
                DisposeUnmanagedResources();
            }
        }
示例#2
0
 /// <summary>
 /// Base constructor.
 /// </summary>
 public DisposableManagedOnlyBase()
 {
     DisposableTracker.Register(this);
 }
示例#3
0
 /// <summary>
 /// Base constructor.
 /// </summary>
 protected DisposableManagedOnlyBase()
 {
     DisposableTracker.RegisterInstance(this);
 }