开发者

Lock keyword and application resets

开发者 https://www.devze.com 2023-03-19 10:52 出处:网络
I have a web service that freezes deadlocks on the lock command. loc开发者_StackOverflowk(typeof(MyServiceType))

I have a web service that freezes deadlocks on the lock command.

loc开发者_StackOverflowk(typeof(MyServiceType))

I feel that this is caused by application pool resets.

Is there any way that app pool resets could cause the lock to become a forever lock?


I can't exactly comment on what is happening with regards to application pool resets, but perhaps you should try locking on a new object, instead?

  private readonly object myLock = new object();

  void DoSomething()
  {
    lock(myLock)
    {
      ...
    }
  }


Not normally.

App pools are process isolated. The only way you can get a problem is when the app pool can't shutdown due to that deadlock. (This would be a DOS and therefore likely a bug in IIS.)

Thinking of it now, really, this could be your problem. You are locking on a Type (typeof MyServiceType). Could you try locking on something else (that perhaps wouldn't prevent unloading the containing assembly from the AppDomain in IIS?). Something like the following is idiomatic:

 public class MyServiceType : //....
 {
      private static readonly Object _lockObject = new Object();

      // ....

      lock(_lockObject)
      {
           ....
      }
0

精彩评论

暂无评论...
验证码 换一张
取 消