WindowsAppSDK (WinUI3) shutdown application before mainwindow is shown? #3278
-
In WindowsAppSDK (WinUI 3) is it possible to shutdown the application specifically in the OnLaunched override before the main window is shown? Application.Exit() does not work until the main window is shown. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Mybe killing process |
Beta Was this translation helpful? Give feedback.
-
The documentation for Microsoft.UI.Xaml.Application.Start gives a bit of a hint. It states: "This runs a message pump internally, and does not return until the application shuts down." What it means by this "message pump" is the GetMessage/DispatchMessage loop. There is more evidence of this in the dispatcher queue documentation where DispatcherQueueController.CreateOnCurrentThread explicitly states that it uses a USER32 message loop. The dispatcher queue is what does the WinUI 3 event processing. This means that all you have to do is exit this loop, and there is a very simple but stupid way of doing that. PostQuitMessage. This will cause GetMessage to exit the loop. Of course, if you are working in C# then you will have to platform invoke, but that should be trivial. |
Beta Was this translation helpful? Give feedback.
The documentation for Microsoft.UI.Xaml.Application.Start gives a bit of a hint. It states:
"This runs a message pump internally, and does not return until the application shuts down."
What it means by this "message pump" is the GetMessage/DispatchMessage loop. There is more evidence of this in the dispatcher queue documentation where DispatcherQueueController.CreateOnCurrentThread explicitly states that it uses a USER32 message loop. The dispatcher queue is what does the WinUI 3 event processing. This means that all you have to do is exit this loop, and there is a very simple but stupid way of doing that. PostQuitMessage. This will cause GetMessage to exit the loop.
Of course, if you are…