我的asp.net应用程序中的单例设计模式 [英] Singleton design pattern in my asp.net application
本文介绍了我的asp.net应用程序中的单例设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的asp.net应用程序中有一个单例设计模式。我有一个静态的ContentStoreCore对象。如果并发用户正在使用该类的相同实例,会发生数据混淆吗?
< span class =code-keyword> public static class FactoryClass
{
private static ContentStoreCore obj = null 跨度>;
私有 静态 readonly < span class =code-keyword> object padLock = new object ();
public static ContentStoreCore GetInstance()
{
lock (padLock)
{
if (obj == null )
{
obj = new ContentStoreCore();
}
}
return obj;
}
}
解决方案
嗨
请参阅以下msdn文章。
http://msdn.microsoft。 com / en-us / library / ff650316.aspx [ ^ ]
I have a singleton design pattern in my asp.net application. I have a static ContentStoreCore object.If concurrent users are using the same instance of the class ,Will data mix up occurs?
public static class FactoryClass
{
private static ContentStoreCore obj = null;
private static readonly object padLock = new object();
public static ContentStoreCore GetInstance()
{
lock (padLock)
{
if (obj == null)
{
obj = new ContentStoreCore();
}
}
return obj;
}
}
解决方案
Hi
Please refer the following msdn article .
http://msdn.microsoft.com/en-us/library/ff650316.aspx[^]
这篇关于我的asp.net应用程序中的单例设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文