Singleton Destructor

C

cody

The error is probably because proteced members do not make sense in a sealed
class. From a sealed class cannot be inherited from but protected members
can be accessed from the class itself and derived classes.

You should make the method private or public instead.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Dan said:
All,

I am developing an Object that wraps an old C library. Baeed upon how the
object will be used I decided the best bet would be to make the object a
singleton.
Additionally, because the object is working with unmanaged resources it
should implement a dispose method to ensure that those resounrce are freed.
Here is the basic code for the object's constructor and dispose method

public sealed class IAClientImport : IDisposable
{

private static volatile IAClientImport instance;
private static object syncRoot = new Object();
private bool _Disposed = false;

private IAClientImport() {}

public static IAClientImport Instance
{

get
{

if ( instance == null )
{
lock ( syncRoot )
{
if ( instance == null )
instance = new IAClientImport();
}
}

return instance;


}


public void Dispose()
{
Dispose( true );
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if ( !this._Disposed )
{

if ( disposing ) { /*Dispose Managed Resources Here*/ }

//Dispose Managed Reources - The Handle To The IA Client Object


}


this._Disposed = true;

}

~IAClientImport()
{
Dispose(false);
}

}


The problem that I am having is that when I attempt to compile the object I get the following two errors

(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' : new protected
member declared in sealed class
(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' is a new virtual
member in a sealed class 'FNIS.InputAccel.IAClientImport'
I am a bit confused as to what I need to change in order to ensure that
the unmanaged resources in the object get disposed of properly while at the
same time holding to the singleton design pattern.
 
G

Guest

All,

I am developing an Object that wraps an old C library. Baeed upon how the object will be used I decided the best bet would be to make the object a singleton.

Additionally, because the object is working with unmanaged resources it should implement a dispose method to ensure that those resounrce are freed.

Here is the basic code for the object's constructor and dispose method

public sealed class IAClientImport : IDisposable
{

private static volatile IAClientImport instance;
private static object syncRoot = new Object();
private bool _Disposed = false;

private IAClientImport() {}

public static IAClientImport Instance
{

get
{

if ( instance == null )
{
lock ( syncRoot )
{
if ( instance == null )
instance = new IAClientImport();
}
}

return instance;


}


public void Dispose()
{
Dispose( true );
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if ( !this._Disposed )
{

if ( disposing ) { /*Dispose Managed Resources Here*/ }

//Dispose Managed Reources - The Handle To The IA Client Object


}


this._Disposed = true;

}

~IAClientImport()
{
Dispose(false);
}

}


The problem that I am having is that when I attempt to compile the object I get the following two errors

(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' : new protected member declared in sealed class

(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' is a new virtual member in a sealed class 'FNIS.InputAccel.IAClientImport'


I am a bit confused as to what I need to change in order to ensure that the unmanaged resources in the object get disposed of properly while at the same time holding to the singleton design pattern.

Any help is appreciated.

Thanks!
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Dan,

I think that it's because the class is sealed, then it has no point in
declare a method protected or virtual, you will no have any derived classes
that can override it. nor access it.


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Dan said:
All,

I am developing an Object that wraps an old C library. Baeed upon how the
object will be used I decided the best bet would be to make the object a
singleton.
Additionally, because the object is working with unmanaged resources it
should implement a dispose method to ensure that those resounrce are freed.
Here is the basic code for the object's constructor and dispose method

public sealed class IAClientImport : IDisposable
{

private static volatile IAClientImport instance;
private static object syncRoot = new Object();
private bool _Disposed = false;

private IAClientImport() {}

public static IAClientImport Instance
{

get
{

if ( instance == null )
{
lock ( syncRoot )
{
if ( instance == null )
instance = new IAClientImport();
}
}

return instance;


}


public void Dispose()
{
Dispose( true );
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if ( !this._Disposed )
{

if ( disposing ) { /*Dispose Managed Resources Here*/ }

//Dispose Managed Reources - The Handle To The IA Client Object


}


this._Disposed = true;

}

~IAClientImport()
{
Dispose(false);
}

}


The problem that I am having is that when I attempt to compile the object I get the following two errors

(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' : new protected
member declared in sealed class
(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' is a new virtual
member in a sealed class 'FNIS.InputAccel.IAClientImport'
I am a bit confused as to what I need to change in order to ensure that
the unmanaged resources in the object get disposed of properly while at the
same time holding to the singleton design pattern.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top