开发者

Disposing of static resources in web service

In a pre-WCF .NET (C#) web service, I have 开发者_如何转开发an expensive IDisposable resource that I'm holding a static (actually ThreadStatic) reference to. (Internally it holds a SqlConnection.) How can I insure that this is disposed when the app pool refreshes, should I simply suppress the FxCop warning and not worry about it, or is there a third option?

Originally the service opened the connection on each request with a using block, but that design was rejected due to a "connection resource issue."


This design will be rejected due to a connection resource issue. If you had problems before, you'll have them again, since you will now be using more SqlServer connections (if it's thread static, then each thread will have one SqlServer and - more importantly - one underlying real connection, even when it's not using the connection and would have returned the underlying connection to the pool).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜