private void Cleanup() { if (IsClosed) { return; } _isClosed = true; if (IsInvalid) { return; } // Save last error from P/Invoke in case the implementation of // ReleaseHandle trashes it (important because this ReleaseHandle could // occur implicitly as part of unmarshaling another P/Invoke). int lastError = PInvokeMarshal.GetLastWin32Error(); ReleaseHandle(); PInvokeMarshal.SetLastWin32Error(lastError); GC.SuppressFinalize(this); }
internal static void SetLastWin32Error(int errorCode) { PInvokeMarshal.SetLastWin32Error(errorCode); }