473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Cross process singleton

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
Nov 16 '05 #1
2 5682
I think that's known as a "virtual singleton", here's the first link on
Google, there may be others:
http://www.codeproject.com/csharp/VirtualSingleton.asp

ok,
aq

"Patrick Tsang" <pt@pat.ca> wrote in message
news:12****************************@phx.gbl...
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

Nov 16 '05 #2
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: E. Robert Tisdale | last post by:
Could somebody please help me with the definition of a singleton? > cat singleton.cc class { private: // representation int A; int B; public: //functions
3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
2
by: FrzzMan | last post by:
The first time I called this function, everything went well, but the second time I called it. An Exception thrown, do you know why? An unhandled exception of type 'System.IO.IOException' occurred...
0
by: Tony Wong | last post by:
I am trying to implement the Singleton Pattern for a assembly (class) which control a common resource on my computer. I need the Singleton behavior within a single process which contain multiple...
35
by: Alex Martelli | last post by:
Having fixed a memory leak (not the leak of a Python reference, some other stuff I wasn't properly freeing in certain cases) in a C-coded extension I maintain, I need a way to test that the leak is...
3
by: John E. | last post by:
I am trying to find a way to not have to reference an object in all my projects, since it is initialized & instantiated in my Common class. I have a 4 tier project (presentation, rules, dal,...
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
5
by: nospam | last post by:
Hi all. I have encountered a "Cross-thread operation not valid" error in a test program I created and although I have came up with a solution I don't like the performance of the program. I...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.