Confusion about the lock statement in C#

后端 未结 6 1264
孤独总比滥情好
孤独总比滥情好 2020-12-05 18:27

This is from MSDN: The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical sectio

6条回答
  •  温柔的废话
    2020-12-05 19:10

    The critical section that it is talking about is the section guarded by the lock statements.

    Any critical section that is locking on the same object will be blocked from getting access.

    It is also important that your lock object be static, because the locks need to be locking (or trying to lock) on the same instance of the lock object.

提交回复
热议问题