Singleton Problems

I have an issue with singleton implementation in C#, my business object has a 3 hash tables this class follows a singleton pattern. I have the following test scenario.I have a test.aspx which populates the hash tables with the data from the database.I have an exe which also instantiates this class to view the refreshed data.I run the aspx first and then run the exe, when the exe is run it says the instance is already present and returns the instance but that instance doesnot have any data in the hash table. My issue is that the singleton is creating a fresh instance or cleaning the data in the hashtable everytime its called from a client could the C# experts throw some light on this.
Who is Participating?
One if the issues that I ran into with the singleton is that it is bound by application domain.  Basically, each exe creates a seperate application domain and therefor (in my experience) can create a new singleton.  The way around this is to use remoting to cross the application domains.  I chose to figure out a different solution at this point but that is what I recall when I ran into a similiar issue.

the aspx and the exe are not using the same singleton as Tuck points out above ...

A centralized source will be required, there are a few methods of doing this ...

1) Web Service
2) Singleton Remoting
3) File Based Persistance
4) DB Based Persistance
5) Shared Memory Based Persistance

naturally each has its positives and negatives .. could you let us know a bit more about your requirements?



vinyel23Author Commented:
Thanks tuck your comment rang a bell i changed my app domain to and the singleton works like a champ...
Thanks again
beware: if an assembly is unloaded so is your singleton ... does this from time to time (unload a domain) depending on your setup.

also the use of this causes problems because you force yourself into a single concurrent app pool ... i.e. you can only process 1 concurrent request.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.