lock keyword in C#

前端 未结 10 908
南旧
南旧 2020-11-30 03:54

I understand the main function of the lock key word from MSDN

lock Statement (C# Reference)

The lock keyword marks a statement block as

10条回答
  •  佛祖请我去吃肉
    2020-11-30 04:20

    You can have performance issues with locking variables, but normally, you'd construct your code to minimize the lengths of time that are spent inside a 'locked' block of code.

    As far as removing the locks. It'll depend on what exactly the code is doing. Even though it's single threaded, if your object is implemented as a Singleton, it's possible that you'll have multiple clients using an instance of it (in memory, on a server) at the same time..

提交回复
热议问题