I’m wondering if this construction will cause an error:
lock(sync)
{
// something
lock(sync)
{
//something
lock(sync)
{
//something
}
}
}
I’ve run this code, and it seems fine, but maybe in some circumstances an error may be thrown?
lockis a wrapper forMonitor.EnterandMonitor.Exit:From the documentation for
Monitor.Enter:Because the calls to
EnterandExitare paired, your code pattern has well defined behaviour.Note, however, that
lockis not guaranteed to be an exception-less construct: