I have a C# Windows Forms Application
I want to show a "There are unsaved changes. Save/Quit/Cancel" style confirmation dialog before the Application shuts down. Potentially also while prevent the Application Shutdown. How do I do that?
Also if the application does not close, what wil happen with the Shutdown Process on a Windows 10?
Depends on the Display technology (WPF/UWP or WinForms), but there is usually a "Closing" Event for each form. Where you can show that MessageBox and even cancel the Form closing.
They are both on the basic class for the Form/Windows:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.closing
https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.closing
The application itself will only close after all forms have closed (this can include hidden ones), so this will prevent the application from closing. However sepereate Forms might still be closed if they do not resist.
If your application will not close and the user does not pick "Force Close", the Shutdown Process of Windows will stop eventually with a silent failure. However that is considerd bad behavior. Indeed a few times I thought it had restarted, but in reality the Shutdown had stalled because of someone.
Especialy Disk operations can cause relevant stalls on application closure. Many Word Processors work on a hidden, temprary file for crash recovery purposes. And thus can always just default writing the state there, if the user does not repsond.