By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

How to implement process wide singleton pattern for assembly using static

P: n/a
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 AppDomains. I use a static
member to count class instance like this,

public __gc class foo: public IDisposable





//! In VS .NET 2003 global variables and static members of native types

// shared across AppDomains.

// With VS .NET 2005, you have the option to share or not share

// across AppDomains.

// __declspec(process) for share static variable across AppDomains.

// __declspec(appdomain) have one instance of static variable per

static Int32 m_refCount = 0;


As per my comment in the code, I thought static members are shared across
AppDomain in VS.NET 2003, But when I run my code in the debugger I see a
new instance of the m_refCount in different instances of the class created
in different AppDomains.

Is static members shared across multiple AppDomains within the same process
under VS.NET 2003 or am I seeing a bug in the IDE Debugger (I am using
VS.NET 2003)?

If static members are not shared across multiple AppDomains within the same
process then how does one implement the singleton pattern under managed C++?

Thanks in advance for your help.
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.