#40 – Application Lifetime

The diagram below shows a simplified view of the lifetime of a WPF application, as defined by the events that the Application class fires.  (The events are underlined).  Click the diagram to see a full-sized version.

The main events fired from Application include:

  • Startup – Application is starting up.
  • Exit – Fired when an application is shutting down.  Shutdown can’t be canceled.
  • Activated – Fired when an application gets focus, i.e. becomes the foreground application
  • Deactivated – Fired when application loses focus, i.e. is no longer the foreground application
  • DispatcherUnhandledException – Fired when an exception is thrown, but not yet handled.  You can choose to handle the exception or not
  • SessionEnding – Fired when Windows is being shut down–due to either logoff or Windows shutdown.  You can cancel the shutdown sequence.

You can add custom code for any of these events by just overriding the OnEventName method in your Application-derived class, e.g. OnStartup.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #40 – Application Lifetime

  1. Pingback: #197 – Override Application Class Methods for Standard Events « 2,000 Things You Should Know About WPF

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: