Does the call to Response.Redirect () inside the used block call Dispose ()?

Possible duplicate:
Response.Redirect (") inside" using {} "

Pretty much that. If I had, for example, a database connection in a using statement and somewhere inside, using an operator that I redirected to another page, would it delete my connection or would I have to manually call it first?

+3
source share
4 answers

Yes, he will absolutely call Dispose. The operator using's point is what Disposeis called in the block finally, so the resource will be set regardless of whether the block completes normally or with an exception.

, IIRC , Response.Redirect ThreadAbortException, , , finally.

+7

. using - try/finally. , try/finally. finally .

+2

.

0

, Dispose() :

, . . using , .

You know that you do not have the first two, because your process does not hang and do not break. You know that you have a third, because the redirection is inside using, so it cannot be.

0
source

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


All Articles