Skip to content

Instantly share code, notes, and snippets.

Created April 30, 2009 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/104477 to your computer and use it in GitHub Desktop.
Save anonymous/104477 to your computer and use it in GitHub Desktop.
class Disposable : IDisposable
{
#if DEBUG
StackTrace stack = new StackTrace();
#endif
readonly Action _action;
public Disposable(Action action)
{
_action = action;
}
public void Dispose()
{
_action();
#if DEBUG
GC.SuppressFinalize(this);
GC.KeepAlive(this);
#endif
}
#if DEBUG
~Disposable() {
Debug.Assert(false, "Disposable was not used correctly " + stack.ToString());
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment