This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
Original Post: Using for purposes other than disposable objects...
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
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.