问题描述
借助 锁
语句确保一个线程不进入code的一个关键部分,而另外一个线程处于临界区。然而,它不会如果工作量为s $ P $垫跨服务器的一个农场工作(例如几的IIS服务器+负载平衡器)。
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 spread across a farm of servers (e.g. a few IIS servers + a load balancer).
.NET是否支持这样的情景?
是否有可用于控制的关键code段由多台计算机上运行的线程的执行任何类?
Does .NET support such a scenario?
Is there any class that can be used to control the execution of a critical code section by threads running on multiple machines?
如果不是,是否有处理此类问题的任何标准方法?
If not, is there any standard method of handling such problems?
推荐答案
如果你有机会到一个集中的SQL Server实例,你可以用它来作为一个分布式的锁协调和使用的和的的存储过程。
If you have access to a centralized SQL Server instance, you can use it to act as a distributed lock coordinator and manage the application locks using the sp_getapplock and sp_releaseapplock stored procedures.
这篇关于使用而不是&QUOT什么;锁定"当code在多台计算机上运行的声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!