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;
}
}
}
Monday, June 16, 2008
C# Singleton
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment