caching - ASP.NET lock() doesn't work -


I try to lock a static string object to reach the cache, lock (block) implemented in my local Does, but whenever I deploy it on the server, it always locks for it. I write every step in the event log to see the process and the lock causes the deadlock on the server. The order immediately after lock () is never executed because I do not see an entry in the event log. The code below is:

  public static string CacheSyncObject = "CacheSync"; Public Static DataWit Getuser () {Datatelle dtUsers = null; If (http.txt.exe.ca ["DTUsers"] = Faucet) {Global.Event Logger.prakash (String.format ("Getuers (Cache Hit: {0}", DTUser.Ro.Count)); DataTable as return (HttpContext.Current.Cache ["dtUsers"] .copy (). DefaultView; } Global.eventLogger.Write ("GetUsers (Cash Cash)"); Lock (cachecink object) {Global. EventLogger.prakash ("GetUseSource () sync object locked"); If (HTTP consort. On.quate ["DTUsers"]! = Null) {Global.Event logger.light ("getuasers (oops), another thread in the cache, release lock"); DataTable as return (HttpContext.Current.Cache ["dtUsers"] .copy (). DefaultView; }  

Global.eventLogger.Write ("GetUsers () SyncObject Lock"); ==> It is never written on the log, so I mean, lock () is never executed.

itemprop = "text">

You are locking on the string, which is generally bad idea in NIT. The NAT runtime actually stores the same uniformed strings at once, so you have little control about who sees the specific string.

I'm not sure how the ASP .NET runtime handles it, but regular .net runtime actually uses the interning for the whole process, which means that between different app docs Internal strings are also shared. In this way you can do deadlock between different instances of the law.


Comments