I occasionally get error in telemetry reports that settings file is corrupted if user shuts down computer while program is running. I already have in place shutdown blocking - program blocks shutdown with ShutdownBlockReasonCreate
, runs Properties.Settings.Default.Save();
and then removes the shutdown block with ShutdownBlockReasonDestroy
. I know that the user didn't press "shut down anyway" because the Serilog logs a message that the ShutdownBlockReasonDestroy
was reached and completed, and that log is saved to disk and properly flushed, but for some reason the settings are not consistently saved.
Is there a way to ensure that settings are saved?
I am using PortableJsonSettingsProvider
0.2.1 from Nuget
[DllImport("user32.dll")]
public extern static bool ShutdownBlockReasonCreate(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pwszReason);
[DllImport("user32.dll")]
public extern static bool ShutdownBlockReasonDestroy(IntPtr hWnd);