private void SetNativeTheme(SafeThemeFileHandle newTheme) { var oldTheme = theme; if (newTheme != null && !newTheme.IsInvalid && !newTheme.IsClosed) { UxThemeExNativeMethods.UxOverrideTheme(newTheme).ThrowIfFailed(); UxThemeExNativeMethods.UxHook().ThrowIfFailed(); theme = newTheme; } else { theme = null; UxThemeExNativeMethods.UxUnhook().ThrowIfFailed(); UxThemeExNativeMethods.UxOverrideTheme(SafeThemeFileHandle.Zero).ThrowIfFailed(); } oldTheme?.Dispose(); }