Assign Dispose Dispose call (IsDisposing) in C #?

Here is the code from MSDN . I don’t understand why the work is not just done in the regular Dispose () method. What is the purpose of using the Dispose (bool) method? Who could call Dispose (false) here?

public void Dispose() 
{
    Dispose(true);

    // Use SupressFinalize in case a subclass
    // of this type implements a finalizer.
    GC.SuppressFinalize(this);      
}

protected virtual void Dispose(bool disposing)
{
    // If you need thread safety, use a lock around these 
    // operations, as well as in your methods that use the resource.
    if (!_disposed)
    {
        if (disposing) {
            if (_resource != null)
                _resource.Dispose();
                Console.WriteLine("Object disposed.");
        }

        // Indicate that the instance has been disposed.
        _resource = null;
        _disposed = true;   
    }
}
+5
source share
4 answers

The finalizer will call Dispose(false)- in this case, you do not touch any of the other managed resources (which may have already been completed).

- , , IDisposable. , .

+14
+3

Dispose (disposing) , , GC.

, Dispose (disposing) , GC appopriately.

0

,

Dispose (disposing) , , GC.

. :

Dispose (disposing) finalizable (.. ) , , GC. Finalizer .

, , :)

0

All Articles