public void Free()
{
// Copy the handle instance member to a local variable. This is required to prevent
// race conditions releasing the handle.
IntPtr handle = m_handle;
// Free the handle if it hasn't already been freed.
if (handle != IntPtr.Zero && Interlocked.CompareExchange(ref m_handle, IntPtr.Zero, handle) == handle)
{
#if WIN32
InternalFree((IntPtr)(((int)handle) & ~1));
#else
InternalFree((IntPtr)(((long)handle) & ~1L));
#endif
}
else
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_HandleIsNotInitialized"));
}
}