using (a) {do something with}
This means that when a code block is executed with a, the program will call a.Dispose. You know that even in the event of an exception, you will have Dispose. In fact:
var a = IDisposable_Something; try{.....}finally{a.Dispose();}
Itโs safer ... actually, but thatโs not the point. The point is to make sure that the resources that need to be cleaned up are executed as soon as the program ends with them.
So the problem with your first example is that if an exception is thrown somewhere along the line, it will not apply to the Dispose() method. The second will be. You always want Dispose to be called if it is, because there is a chance that the IDisposable classes will not be written correctly and it will not have code to make sure that unmanaged resources are cleared even if Dispose() not called (this usually done in the finalizer). LInk to delete the template.
The only time I have ever seen that deployment can be complicated is the WCF service proxy (and you can work around this problem). There is an error in which if the proxy occasionally throws an exception, it raises another exception in the Dispose() method.
http://blogs.msdn.com/b/jjameson/archive/2010/03/18/avoiding-problems-with-the-using-statement-and-wcf-service-proxies.aspx
Other than that, you should usually try to put the IDisposable object in the using statement.
kemiller2002
source share