Managing AppDomains using the "Using" statement

Jun 24, 2009 at 2:14 PM
Edited Jun 24, 2009 at 2:20 PM

In response to Robin's question last night regarding the management of AppDomains using the "Using" statement the short response is "No, you cannot use the 'Using' statment.".

To quote MSDN....

"The using statement allows the programmer to specify when objects that use resources should release them. The object provided to the using statement must implement the IDisposable interface. This interface provides the Dispose method, which should release the object's resources."

This mirrors what Peter said last night; an AppDomain object does not have the IDisposable interface implemented.  The AppDomain class only implements the _AppDomain and IEvidenceFactory interfaces but not the IDisposable interface.  Without this interface the Using construct cannot manage the object in question.  I tried to use "Using" all the same just to confirm what MSDN said and sure enough I get a code error identifying that the Using cannot be used because the IDisposable interface is not implemented.



Have I used Using enough to overuse it or was its use useful to all you using this site?

Jun 24, 2009 at 3:36 PM

Very cool catch gq_stud! :>  Great information.  But I have to admit, I don't believe I mentioned AppDomain doesn't implement IDisposable, I think I said IF it implements, in other words, I was cluesless on that fact which you found out great information about!  Thanks for sleuthing and letting us know about it!  Great work.