What to use instead of the “lock” statement when the code is running on multiple machines?

后端 未结 5 2137
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 10:02

The lock statement ensures that one thread does not enter a critical section of code while another thread is in the critical section. However, it won\'t work if the workload is

5条回答
  •  面向向阳花
    2021-02-13 10:46

    The lock statement is only useful for sharing resources within a process.

    The Mutex and EventWaitHandle classes are useful for sharing resources among multiple processes on a single machine when using names that start with "Global\".

    Beyond that, you will have to implement something outside .NET, like using sp_getapplock/sp_releaseapplock on a shared SQL database.

提交回复
热议问题