Visual Studio is an IDE for creating software.
Download: Visual Studio Community More: WiX Toolset build tools
Application startup / shutdown
by George Frias
Created: 2021-01-03 | Updated: 2021-03-08

- Introduction
- Custom startup - Create your own procedure to run on startup.
- Calling shutdown
- Crashing - Problems that I've come across.
Introduction
The default setting for startup (Startup URI under My Project ➸ Application) is MainWindow.xaml, and for shutdown is (Shutdown mode: under My Project ➸ Application) is On last window close.
If you need to run code prior to window launch, you can in Application.xaml.vb. Select the Startup combo item under the (Application Events) combo item. You can do the same for application shutdown, just select Exit instead of Startup.
For a custom startup, refer to Custom startup below.
Custom startup
It's actually quite simple to create your own startup process, there are two steps.
1. Application.xaml: Replace StartupUri="MainWindow.xaml" with Startup="AppStartup"
2. Application.xaml.vb: Add Private Sub AppStartup(sender As Object, e As StartupEventArgs)
Calling shutdown
1. My.Application.Shutdown()
2. End
Crashing
If you change the name of your window and the app will-not-start/starts-crashing it could be two things. 1. The XAML code for the name of the window does not reflect the change in window name and 2. the Startup URI is still set to the previous window name.