From the resource clean-up perspective, why there are Response.Close() and Response.Dispose() and which one is more comprehensive (call the other one) ?
From the resource clean-up perspective, why there are Response.Close() and Response.Dispose() and which one
Share
Where both methods are provided the implementation of
Disposeshould callClose. It is a good idea to use the using statement to ensure thatDisposeand thereforeCloseis called, even if there is an exception.In other words do this:
Not this:
One difference between closing and disposing an object is that when you dispose an object it usually is not possible to use the object any more (attempting to do so may cause an ObjectDisposedException to be thrown), but after calling Close it may be possible to still use the object.
Note that if you are talking about ASP.NET then you shouldn’t normally call Close or Dispose on the Response object.