Lock only on an Id

前端 未结 4 639
醉梦人生
醉梦人生 2021-01-18 14:31

I have a method which needs to run exclusivley run a block of code, but I want to add this restriction only if it is really required. Depending on an Id value (an Int32) I w

4条回答
  •  情歌与酒
    2021-01-18 15:17

    I use a similar approach to lock resources for related items rather than a blanket resource lock... It works perfectly.

    Your almost there but you really don't need to remove the object from the dictionary; just let the next object with that id get the lock on the object.

    Surely there is a limit to the number of unique ids in your application? What is that limit?

提交回复
热议问题