<分区> 分区>
我写了一段关于单例模式实现的代码。不确定其正确性。请给些建议。谢谢。
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);
}
