rot*_*man 3 .net c# multithreading synchronization
我想我失去了一些东西有关的正确行为Monitor.Enter和Monitor.TryEnter.这是我编写的一段代码,用于将问题与其余代码分开:
object lockObj = new object();
bool result = Monitor.TryEnter(lockObj);
Console.Write(result);
Run Code Online (Sandbox Code Playgroud)
结果总是如此true.这里没有惊喜.
object lockObj = new object();
Monitor.Enter(lockObj);
bool result = Monitor.TryEnter(lockObj);
Console.Write(result);
Run Code Online (Sandbox Code Playgroud)
但这次也是true.所以是否lockObj被锁定Monitor.Enter?请给我一些新的看法.