What is the difference between Response.Close () and Response.Dispose ()?

In terms of cleaning resources, why exist Response.Close()and Response.Dispose()which one is more complete (another challenge)?

+3
source share
3 answers

If both methods are provided, the implementation Disposeshould call Close. It is recommended that you use the using statement to ensure that, Disposeand therefore, Closeis called, even if there is an exception.

In other words:

using (Response response = ...)
{
    // ...
}

Not this:

Response response = ...;
// ...
response.Close(); // If there is an exception this might never get called!

, ( ObjectDisposedException), Close .

, ASP.NET, Close Dispose Response.

+7

Finalize Dispose

, Dispose. , name Close. , Dispose Close, Dispose. . Close . , System.

/ Do not make this method virtual.
// A derived class should not be allowed
// to override this method.
public void Close()
{
   // Call the Dispose method with no parameters.
   Dispose();
}

, , .

+1

Response.Close() . Response.Dispose() - , IDisposable .

, Response.Close() Response.Dispose().

Reflector

0

Source: https://habr.com/ru/post/1782317/


All Articles