Using for purposes other than disposable objects…


Doug asks:


re: A lock statement with timeout…


I’ve done this trick before to deal with common patterns in numerous methods. Usually lock acquisition, but there are some others. Problem is it always feels like a hack since the object isn’t really disposable so much as "call-back-at-the-end-of-a-scope-able".


Doug,


When we decided the using statement, we decided to name it “using” rather than something more specific to disposing objects so that it could be used for exactly this scenario.

Comments (4)

  1. Doug McClean says:

    Really? Cool. I don’t feel as dirty anymore. :)

    I will take that as license to keep doin’ what I’m doin’.

  2. Eric Gunnerson (of the C# design team) says they planned for the use of using statements for purposes other than deterministic finalization of unmanaged resources.

  3. Eric Gunnerson (of the C# design team) says they planned for the use of using statements for purposes other than deterministic finalization of unmanaged resources.

  4. John says:

    But that was a mistake wasn’t it?