并调用的Response.Redirect()using块调用Dispose()内部? [英] Does calling Response.Redirect() inside of a using block call Dispose()?

查看:181
本文介绍了并调用的Response.Redirect()using块调用Dispose()内部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
的Response.Redirect(“”的)内部及ldquo;使用{}”的

差不多了。如果我有,例如,在使用说明和地方,using语句内部数据库的连接我重定向到另一个网页,它会处理我的连接,或者我必须先手动调用它呢?

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

推荐答案

是的,这绝对会叫的Dispose 。一个使用声明的一点是,的Dispose 被称为在最后块,这样的资源将被配置在块是否正常或异常结束。

Yes, it would absolutely call Dispose. The point of a using statement is that Dispose is called in a finally block, so the resource will be disposed whether the block completes normally or with an exception.

有这里有一个的轻微的皱纹在IIRC,的Response.Redirect 抛出一个 ThreadAbortException 如果它抓住了,它会自动重新抛出,但是这不应该影响一个最后块。

There's a slight wrinkle here in that IIRC, Response.Redirect throws a ThreadAbortException which will automatically rethrow if it's caught, but that shouldn't affect a finally block.

这篇关于并调用的Response.Redirect()using块调用Dispose()内部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆