Freigeben über


Start using using today! [A bit about the IDisposable interface and the using statement]

**

This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

Comments

  • Anonymous
    September 18, 2007
    Hi I have read that the try-catch-finally block slows down the program. So, is it really a good idea that we use too many using block?

  • Anonymous
    September 19, 2007
    Shishir0610, It's my understanding that throwing and catching an exception can introduce a bit of a performance penalty, but that simply entering/exiting a try/finally block is not itself very costly at all. In other words, try/catch/finally is not a performance issue in general, but in the exceptional (i.e., rare) case there is some cost associated with the throw/catch. For more information, I refer you to Rico Mariani's blog post "Exception Cost: When to throw and when not to" (http://blogs.msdn.com/ricom/archive/2003/12/19/44697.aspx). There's good info in the comments, so they're worth reading as well. In summary, it's my understanding that the using statement should not generally slow a program down by any noticeable amount - and the correctness/reliability/predictability benefits that you get from it are well worth that cost.