Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Created January 8, 2015 22:52
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 jonpryor/96f4bbb482b3a58613ba to your computer and use it in GitHub Desktop.
Save jonpryor/96f4bbb482b3a58613ba to your computer and use it in GitHub Desktop.
// SafeHandle.Close()...
using System;
using System.Runtime.InteropServices;
class MySafeHandle : SafeHandle {
public MySafeHandle ()
: base (IntPtr.Zero, ownsHandle:false)
{
}
protected override bool ReleaseHandle ()
{
return true;
}
public override bool IsInvalid {
get {return base.handle == IntPtr.Zero;}
}
}
class App {
public static void Main ()
{
var h = new MySafeHandle ();
h.Close ();
h.Close ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment