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

前端 未结 5 1579
执念已碎
执念已碎 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 11:49

    I believe that you can use Monitor.TryEnter().

    The lock statement just translates to a Monitor.Enter() call and a try catch block.

提交回复
热议问题