I suspect this is a very dumb question: what is the correct syntax for an interruptible lock statement in C#? E.g. get lock; if lock is interrupted before locked code finishes, return false out of the enclosing method. Probably totally the wrong terminology… Thanks.
Share
You can have a timeout while aquiring a lock using
Monitor.TryEnter; and likewise, within a lock you can do things likeMonitor.Wait/Monitor.Pulseto temporarily yield the lock, but you can’t be interrupted as such.The main time interrupt applies might be in Thread.Sleep, which can be interrupted with Thread.Interrupt – but again, this won’t yank control out of an executing method block.
What exactly is it that you are trying to achieve? With more context we can probably help more…