Cross process singleton

P

Patrick Tsang

I have a question here don't know how to solve it...I
already spend quite a bit of time doing research for it,
but cannot find a good answer for it...

I want to create a .NET assembly which have delegate
event. I need it to be singleton so no matter how many
applications create instance of it, it will be always has
on instance of it.

Here is my singleton class code:
public sealed class Singleton
{
private static volatile Singleton m_oInstance = null;
private readonly static object m_oSyncObj = new object();\
private static int m_iNumOfReference = 1;

public static Singleton Instance
{
get
{
if (m_oInstance == null)
{
lock(m_oSyncObj)
{
if (m_oInstance == null)
{
m_oInstance = new Singleton();
}
}
}

m_iNumOfReference ++;

return m_oInstance;
}
}
}

I created a little Windows application for testing. If I
only run one instance of that windows application and
works fine, it .but when I run two or more instance of
that windows application then each of them create its own
instance of the "Singleton" object.

What the end goal is. when one of the windows application
update the object then other windows application will get
notify. because they are resisted for the events.

Thank a LOT!!!

Cheers
Patrick
 
S

sadhu

Well, static variables are only shared within an AppDomain, not even
within a process. I'd suggest you use Remoting to talk to the singleton
object, in fact, there is explicit support for Singletons in Remoting.

Regards
Senthil
 

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