【发布时间】:2017-08-23 22:14:34
【问题描述】:
如果我有这样的方法:
public class Main()
{
public void Start()
{
if(//Check if another thread already invoked this method and its in processing//)
DoSomething();
}
void DoSomething()
{
//Some code in here
}
}
如何使用锁来检查一个线程是否已经在执行 DoSomething() 然后跳过它?
我知道锁会让其他调用等待,但我想跳过而不是等待并执行。
【问题讨论】:
标签: multithreading c#-4.0 thread-safety locking