WPF implementations perform certain logic when a computer restarts or shuts down

Source: Internet
Author: User

The Sessionending event of the application class is the response when the computer shuts down or restarts (session end event),

So just add sessionending to the App.xaml.

<x:class= "Drivereasywpf.app"             xmlns= "http// Schemas.microsoft.com/winfx/2006/xaml/presentation "             xmlns:x="/http/ Schemas.microsoft.com/winfx/2006/xaml "             StartupUri=" MainWindow.xaml "  Startup= "Application_Startup"  sessionending= "Application_sessionending" >
View Code

And this is done in the background code:

private void Application_sessionending (object sender, SessionEndingCancelEventArgs e)        {             //your code        }
View Code

But Windows has no sessionending event, so if you want to listen to a computer shutdown or restart in a window,

Because the application class is used throughout the WPF project, in the background code of the other windows, such calls can be:

Public MainWindow ()        {            InitializeComponent ();             App.Current.SessionEnding + = current_sessionending;        }              private void Current_sessionending (object sender, SessionEndingCancelEventArgs e)        {            throw new NotImplementedException ();        }
View Code

Through the App. Current. sessionending + = current_sessionending;

WPF implementations perform certain logic when a computer restarts or shuts down

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.