| Author: Neeraj Saluja 09 May 2008 | Member Level: Gold Points : 2 |
With .NET there are more simpler ways to have the Singleton class, see the simpler implementation below :
public class MySingletonClass {
private static readonly MySingletonClass _instance = new MySingletonClass();
public static MySingletonClass Instance { get { return _instance; } }
private MySingletonClass() { // Have a private constructor so that one cannot create the individual instances of this class }
//... Other Methods Follows }
Also, you mentioned that it gets challenging in multi threaded and asynchronous calls environment, but there are simple solutions to it as well. I advice all to look at the lock() method of System.Threading class, it would be really helpful for all.
But Pranjan, no doubt a nice attempt. Cheers !!!
|