The Application Life Cycle

In WPF, applications go through a straightforward life cycle. Shortly after your application begins, the application object is created. As your application runs, various application events fire, which you may choose to monitor. Finally, when the application object is released, your application ends.

Creating an Application Object

The simplest way to use the Application class is to create it by hand. The following example shows the bare minimum: an application entry point (a Main() method) that creates a window named Window1 and fires up a new application:

using System;
using System.Windows;

public class Startup
{
    [STAThread()]
    static void Main()
    {
// Create the application. Application app = new Application(); // ...

Get Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.