G
GobinathP
Hi,
I'm writing a C# Windows Service and I collect some data inside it. Now I
need to expose this to UI clients. I intend to expose a class which the
clients can talk to. The clients can be COM clients. This I'm able to do.
Now if I want to make the c# component a singleton what should I do?
I tried these
1) deriving from ICustomFactory
public MarshalByRefObject CreateInstance(Type serverType)
{
return singletonObject; // where singletonObject is static object of the
class.
}
2)
public class URTServiceProvider : System.ServiceProcess.ServiceBase,
IUrtPlatformManager
{
...............................
public static URTServiceProvider singletonObject;
static void RegisterInner()
{
singletonObject = new URTServiceProvider();
System.Runtime.InteropServices.ExtensibleClassFactory.RegisterObjectCreation
Callback(new
System.Runtime.InteropServices.ObjectCreationDelegate(singletonObject.Activa
te));
}
public IntPtr Activate(IntPtr Aggregator)
{
return (IntPtr)(IUrtPlatformManager)this; //get an error here due to
invalid type casting
}
//This is the static initializer.
static URTServiceProvider()
{
RegisterInner();
}
........................
}
Any Ideas???
Thanks,
Gobi.
I'm writing a C# Windows Service and I collect some data inside it. Now I
need to expose this to UI clients. I intend to expose a class which the
clients can talk to. The clients can be COM clients. This I'm able to do.
Now if I want to make the c# component a singleton what should I do?
I tried these
1) deriving from ICustomFactory
public MarshalByRefObject CreateInstance(Type serverType)
{
return singletonObject; // where singletonObject is static object of the
class.
}
2)
public class URTServiceProvider : System.ServiceProcess.ServiceBase,
IUrtPlatformManager
{
...............................
public static URTServiceProvider singletonObject;
static void RegisterInner()
{
singletonObject = new URTServiceProvider();
System.Runtime.InteropServices.ExtensibleClassFactory.RegisterObjectCreation
Callback(new
System.Runtime.InteropServices.ObjectCreationDelegate(singletonObject.Activa
te));
}
public IntPtr Activate(IntPtr Aggregator)
{
return (IntPtr)(IUrtPlatformManager)this; //get an error here due to
invalid type casting
}
//This is the static initializer.
static URTServiceProvider()
{
RegisterInner();
}
........................
}
Any Ideas???
Thanks,
Gobi.