IApplicationLifetimeAware Interface
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Defines methods that application extension services can optionally implement in order to respond to application lifetime events.
Assembly: System.Windows (in System.Windows.dll)
The IApplicationLifetimeAware type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Exited | Called by an application immediately after the Application::Exit event occurs. |
![]() | Exiting | Called by an application immediately before the Application::Exit event occurs. |
![]() | Started | Called by an application immediately after the Application::Startup event occurs. |
![]() | Starting | Called by an application immediately before the Application::Startup event occurs. |
You can add extension services to an application using XAML or procedural code with the Application::ApplicationLifetimeObjects property.
Application extension services must implement the IApplicationService interface in order to perform start and stop operations. Additionally, application extension services can implement the optional IApplicationLifetimeAware interface in order to perform operations immediately before and after the Application::Startup and Application::Exit events.
The following list indicates the order in which application lifetime events occur and the IApplicationService and IApplicationLifetimeAware methods are called:
The application calls the IApplicationService::StartService method for each application service.
The application calls the Starting method for each IApplicationLifetimeAware service.
The Application::Startup event occurs.
The application calls the Started method for each IApplicationLifetimeAware service.
The application runs until the stop sequence is initiated by user action. This typically occurs when the user closes the application or browser window, or navigates to a new Web page.
The application calls the Exiting method for each IApplicationLifetimeAware service.
The Application::Exit event occurs.
The application calls the Exited method for each IApplicationLifetimeAware service.
The application calls the IApplicationService::StopService method for each application service.
The application calls each service method one time per service. These methods are called in the order that the services were registered, except that the StopService methods are called in the opposite order. This enables orderly cleanup.
