class Singleton
{
private static volatile Singleton _instance;
private static object _lock = new object();
private Singleton() { }
public static Singleton Instance
{
get
{
if (_instance == null)
{
// Locking makes Singleton thread-safe
lock (_lock)
{
if (_instance == null)
{
_instance = new Singleton();
}
}
}
return _instance;
}
}
}
Showing posts with label singleton. Show all posts
Showing posts with label singleton. Show all posts
Monday, June 16, 2008
C# Singleton
Subscribe to:
Posts (Atom)