S
sameer
guys,
envirnment : C#, VS 2008, .Net 3.5 framework
i am trying to create a single instance of a class within a dll, this class
would be called both from a webservice application as well as invoked locally
from an exe on the same machine. the requriement is to make sure that only
one instance of this class is created
a. no matter how many time this class is initialized
b. no matter if it is locally or remotely
there cannot bemore then one instance of this object ever i.e only one
instance would server all the calls.
using singleton pattern below is the code that i wrote :
public class mysingletonclass
{
private static volatile mysingletonclass _Instance = null;
public static mysingletonclass GetInstance()
{
if (_Instance == null)
{
lock (_Lock)
{
if (_Instance == null)
{
_Instance = new mysingletonclass ();
}
}
}
return _Instance;
}
but when seems that it creates an instace for every application that invokes
it, i.e if the webserice calls it , for all the calls it uses the same
instance where as if an exe invokes it it creates a new instance then use
that same one, again my reuqirement is to make sure that only one instance of
this class exists on the machine level and it is served to all client.
please suggest!
thanks
sameer
envirnment : C#, VS 2008, .Net 3.5 framework
i am trying to create a single instance of a class within a dll, this class
would be called both from a webservice application as well as invoked locally
from an exe on the same machine. the requriement is to make sure that only
one instance of this class is created
a. no matter how many time this class is initialized
b. no matter if it is locally or remotely
there cannot bemore then one instance of this object ever i.e only one
instance would server all the calls.
using singleton pattern below is the code that i wrote :
public class mysingletonclass
{
private static volatile mysingletonclass _Instance = null;
public static mysingletonclass GetInstance()
{
if (_Instance == null)
{
lock (_Lock)
{
if (_Instance == null)
{
_Instance = new mysingletonclass ();
}
}
}
return _Instance;
}
but when seems that it creates an instace for every application that invokes
it, i.e if the webserice calls it , for all the calls it uses the same
instance where as if an exe invokes it it creates a new instance then use
that same one, again my reuqirement is to make sure that only one instance of
this class exists on the machine level and it is served to all client.
please suggest!
thanks
sameer