Application startup / shutdown

Computer

Home Computer Computer

Visual Studio 1. Projects

End product features 1. Help section 2. Installation

WPF programming 1. Startup / shutdown 2. Windows

Application startup / shutdown

by George Frias
Created: 2021-01-03 | Updated: 2021-03-08

info.png WPF stands for Windows Presentation Foundation.
  1. Introduction
  2. Custom startup - Create your own procedure to run on startup.
  3. Calling shutdown
  4. 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.