我写了一段关于单例模式实现的代码。不确定其正确性。请给点建议。谢谢。单例实现
public class Singleton
{
public Singleton Instance
{
get
{
if (_instance == null)
{
if (_mutexCreation.WaitOne(0))
{
try
{
if (_instance == null)
{
_instance = new Singleton();
}
}
finally
{
_mutexCreation.ReleaseMutex();
_eventCreation.Set();
}
}
else
{
_eventCreation.WaitOne();
}
}
return _instance;
}
}
private Singleton() { }
private static Singleton _instance;
private static Mutex _mutexCreation = new Mutex();
private static ManualResetEvent _eventCreation = new ManualResetEvent(false);
}
请用任何语言对此进行标记,以便从该社区接收专家。 :) – sarnold 2011-04-15 08:31:24
它看起来像C#... – shoosh 2011-04-15 08:35:42
我刚刚标记。 :) – lichaoir 2011-04-15 08:49:10