Is there a “try to lock, skip if timed out” operation in C#?

前端 未结 5 1567
执念已碎
执念已碎 2020-12-23 11:17

I need to try to lock on an object, and if its already locked just continue (after time out, or without it).

The C# lock statement is blocking.

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 12:00

    You'll probably find this out for yourself now that the others have pointed you in the right direction, but TryEnter can also take a timeout parameter.

    Jeff Richter's "CLR Via C#" is an excellent book on details of CLR innards if you're getting into more complicated stuff.

提交回复
热议问题