Application Exit Event

-->

In a multithreading program, Application.Exit will not terminate all your threads instead you are only exiting from the current thread context, while leaving any started foreground threads running. In this case you should take measures to kill your other threads, either in the main function or when in the OnClose event of your main form. Oct 02, 2009  We know Word Object model provides an event handler called ApplicationQuit, which will be triggered when the application quits, but we don’t have any such events for Excel (even for PowerPoint and some other Office applications). In order to workaround this issue, first thing that will come in our mind is to use an Office. I need some help in application exit handling. My application has multiple Activity say: - EntryAct, Act1, Act2. When user presses home key on any of these Activities, I need to do som.

Definition

Application Exit Event Wpf

Occurs when the application is about to shut down.

Examples

The following code example displays two forms and exits the application when both forms are closed. When the application starts and exits, the position of each form is remembered. This example demonstrates using the ApplicationExit event to know when the form positions should be persisted to the file, and when the FileStream should be closed.

The class MyApplicationContext inherits from ApplicationContext and keeps track of when each form is closed, and exits the current thread when they both are. The class remembers the position of each form when it is closed. When the ApplicationExit event occurs, the class writes the positions of each for the user to the file. The form position data is stored in a file titled appdata.txt that is created in the location determined by UserAppDataPath. The Main method calls Application.Run(context) to start the application given the ApplicationContext.

This code is an excerpt from the example shown in the ApplicationContext class overview. See ApplicationContext for the whole code listing.

Remarks

Application

You must attach the event handlers to the ApplicationExit event to perform unhandled, required tasks before the application stops running. You can close files opened by this application, or dispose of objects that garbage collection did not reclaim.

Because this is a static event, you must detach any event handlers attached to this event in the ApplicationExit event handler itself. If you do not detach these handlers, they will remain attached to the event and continue to consume memory.

Applies to

See also

  • Exit()Exit()Exit()Exit()
-->

Wpf Application Exit Event Not Called

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Unity application exit event

Application.applicationexit Event C#

Occurs just before an application shuts down and cannot be canceled.

Namespace:System.Windows
Assembly: System.Windows (in System.Windows.dll)

Remarks

You can detect when an application shuts down by handling the Exit event. This allows your application to perform common application shutdown tasks, including saving data for the next application session and logging.

Important Note:

An Exit event handler should not include long-running, re-entrant, or cyclic code, such as resetting the Silverlight plug-in's Source property.

Examples

The following code shows how to handle Exit using markup and code-behind.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Qt Application Exit Event

Reference