Skip to main content
 首页 » 编程设计

c#之为什么要使用 Mutex 来锁定

2024年06月03日42Free-Thinker

为什么有人会使用新的互斥锁来进行锁定?

public class Job 
{ 
    private static Mutex mutex = new Mutex(); 
 
    public void Execute(Context context) 
    { 
        lock (mutex) 
        { 
            // some work here 
        } 
 
        // some more work here 
    } 
} 

请您参考如下方法:

如果这真的是所述 Mutex 的唯一用途,那么它确实没有意义。一个普通的 object 就足够了。