asp.net 中使用如下的静态属性,当服务器请求很多时,是否会产生死锁?
如果会,怎样避免?有没有更好的方法来读取配置? private static string _ConnectionString = String.Empty ;
public static string ConnectionString
{
get{
   if (_ConnectionString==string.Empty )
   {
_ConnectionString = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString") ;
   }    return _ConnectionString ;
   }
}

解决方案 »

  1.   

    >>是否会产生死锁?no, since you are not using locks! but your implementation is not thread-safe, seeImplementing Singleton in C#http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp
      

  2.   

    but since your value is readonly, i think it should not be a problem
      

  3.   

    ASP.NET  中最好不要使用静态属性,因为很多用户在线的话(或者进行压力测试),很可能导致静态属性保存值丢失!
    .NET 开发Winform则可以使用.
      

  4.   

    真的会丢失?
    那asp.net读取配置的最高效的方法是怎么样的,难道对于每个request都要读取一下配置文件么
      

  5.   

    你的写法可以,已经回答了dinglantao(阿paul)所说的“丢失”的问题。