Using Interface to dispose and null and object
- From: "Daniel Jeffrey" <daniel_c_jeffrey@xxxxxxxxxxx>
- Date: Mon, 10 Dec 2007 08:19:11 +1000
I may be on the wrong track here but I thought I could do this, but it isn't working.
I have a class which I have used a interface to define.
This class is then inherited from, and many of them are used (conditionally) on a form.
In order to simplify my dispose area, I thought I could use the interface to dispose and null the items, but it doesn't seem to work.
Eg.
public interface IDataModule : IDisposable
{ ... }
class ProductsDM : Candle.DataModule, IDataModule
{ ... }
class StatusDM : Candle.DataModule, IDataModule
{ ... }
Form Code
_____________
IDataModule CurrentModule;
Load method...
switch (SetupMode)
{
case SetupFormMode.SETUP_PRODUCTS:
{
ProductsModule = new DataModules.ProductsDM(....);
CurrentModule = ProductsModule;
}
break;
case SetupFormMode.SETUP_STATUSES:
{
StatusModule = new DataModules.StatusDM(....);
CurrentModule = StatusModule;
}
break;
}
Unload Method
if (CurrentModule != null)
CurrentModule.Dispose();
CurrentModule = null;
Now if I put a watch on CurrentModule and the Actually objects, the CurrentModule is null, but the others are fine.
Any help would be great.
Daniel
.
- Follow-Ups:
- Re: Using Interface to dispose and null and object
- From: Jon Skeet [C# MVP]
- Re: Using Interface to dispose and null and object
- Prev by Date: Re: C# Wrapper into unmanged code
- Next by Date: Re: Using Interface to dispose and null and object
- Previous by thread: Re: Web forms
- Next by thread: Re: Using Interface to dispose and null and object
- Index(es):
Relevant Pages
|
Loading