View Full Version : IDisposable
Anonymous
02-24-2005, 09:05 PM
I am trying to use the IDisposable (.NET Framework) interface on one of my objects that keeps a thread around to listed for WMI events.
Is there something I need to call on the IApplicationContext to tell the container to shutdown and dispose all of it's objects?
Rick Evans
02-25-2005, 05:58 AM
Hi Crow
Nice catch, you've flushed out an oversight in the current codebase... IApplicationContext and IObjectFactory should both implement IDisposable (the IDisposable interface is first added further down the inheritance tree in the IConfigurableApplicationContext and IConfigurableObjectFactory interfaces respectively).
The fix for this will be in the CVS head today. The final 0.6 release is only a few weeks away (less than a month... well, thats the plan), so hopefully this ain't too much pain.
As a temporary workaround, if you cast your IApplicationContext reference to IConfigurableApplicationContext (and wrap that in a using block), you will be able to call Dispose()... this will take care of cascading the Dispose() call to any singleton objects currently sitting in the context. Note that prototype objects will not be Dispose()d of by the container ('cos the container doesn't keep a reference to prototype objects).
To wit...
public static void Main ()
{
using (IConfigurableApplicationContext ctx = new XmlApplicationContext ("services.xml"))
{
// use ctx...
}
// you could also just call Dispose() explicitly...
IConfigurableApplicationContext ctx = new XmlApplicationContext ("services.xml");
// use ctx...
ctx.Dispose();
}
Ciao
Rick
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.