Skip to content

Implicitly scoped lock statement #2451

Discussion options

You must be logged in to vote

@marksmeltzer wrote:

Same rationale as was used for simplifying using, and I love that simplification.

The simplification for using makes sense because the vast majority of using statements finish at the end of the enclosing block:

{
    // code

    using (var thing = ...) 
    {
        // more code
    }
}

However, because of the need for lock statements to enclose as little as possible, my experience is that those blocks typically finish well before the enclosing block:

{
    // code

    lock (_thing) 
    {
        // more code
    }

    // yet more code
}

Creating a variation of lock that encourages longer lock retention would be a bad idea.

I'd also offer the observation that u…

Replies: 12 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YairHalberstadt
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
9 replies
@theunrepentantgeek
Comment options

@333fred
Comment options

@colejohnson66
Comment options

@333fred
Comment options

@jaredpar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Converted from issue

This discussion was converted from issue #2451 on October 26, 2020 11:26.