New features in Windows Vista development (1)-Restart manager restart Manager

Source: Internet
Author: User

(During this time, I have accumulated some things in the Vista compatibility lecture and subsequent support. I hope to share it with you. Let's start with this article, I will release some content related to Vista development in the near future .)

Since we started using computers, restarting has always been the final line we used to "solve the problem", and application updates have become even more so. Many problems have become simple due to the restart. However, as the system we use becomes more complex, restarting becomes increasingly unacceptable, can you imagine that you need to close 20 windows and wait 10 minutes to start all system services? What you update may only be a small bug in the media player. Windows UpdateMany people may have noticed the new features of Microsoft's Windows Update System, which allows you to delay new startup operations. For example: Figure: We can just click Close and restart later.
Figure: system update prompt in Vista Figure: the system automatic update in Vista is downloading and installing the update package. This feature makes our system updates more user-friendly, we don't have to be forced to restart our computer. Restart ManagerHowever, if our updates are more intelligent, We can automatically close our running application and start it automatically after the update is complete, isn't it better? The restart manager is designed to implement such a function. Let's take a look at the effect of the restart manager. Assume that you have not completed a document before work and left half of the written files on the screen. If Word 2007 needs to be updated in the middle of the night, then, the Vista system will call the restart manager to notify Word 2007 to perform the security close action. When Word 2007 of the restart manager can receive the Security close message, it automatically saves unfinished documents and closes all its windows. After the update is complete, the restart manager will notify Word 2007 to start and help it restore its original status; this includes not only unfinished documents, but also the position of the window, the position of the cursor, and other content related to the user's use environment. At the same time, when we design the update installation package, we can also call the restart manager API to send a message to the application to close and restart the application.
Figure: the installation package that uses the restart manager API will give a friendly prompt. We can see that the restart manager can help us improve the user experience while updating the application, basically, the user's work process is not disturbed by the update program, but can focus on the work he is handling. How to restart the managerWindows Vista has built-in support for the restart Manager. The system can automatically send a close message to the application before installing the update package, and send a start message after the installation is complete. What our applications need to do is to handle these messages and strive for them. 1. registration supports the restart manager NativeMethods. registerApplicationRestart (commandLineReturnValue, // The primary key 0 that uniquely identifies the current State); [DllImport ("kernel32.dll", CharSet = CharSet. auto)] internal static extern uint RegisterApplicationRestart (string pszCommandline, int dwFlags); the above lists calls to the RegisterApplicationRestart API implemented by c # code, registerApplicationRetart is used to register the system API of the current application. After it is called, the system will know that the application supports the restart manager function. At the same time, we can transmit a commandLineRetureValue parameter while registering. Parameters will be returned to the application by the restart manager as command line parameters. 2. response ENDSESSION_CLOSEAPP system message // private const int ENDSESSION_LOGOFF = 0x8; private const int WM_QUERYENDSESSION = 0x0011; private const int ENDSESSION_CLOSEAPP = 0x1; protected override void WndProc (ref Message m) {base. wndProc (ref m); if (m. msg = WM_QUERYENDSESSION) {if (m. LParam. toInt32 () = ENDSESSION_CLOSEAPP) {// here we can save the application status }}} in this code, we first define the static value of the system message, then, a standard system message response method is used to check whether the message we receive comes from the restart manager; If yes, we need to save the application status, such as using files, serialization, and even database for storage. 3. test the startup parameters and restore the application state private void Form1_Load (object sender, EventArgs e) {string [] args = Environment. getCommandLineArgs (); if (args. length> 1) {String commandLineReturnValue = args [1]; // start restoring Application Status} if the application is started by the restart manager, then we can obtain the parameter we passed in when we registered in the second command line parameter. With this parameter, we can restart the program. As we can see, the restart manager only defines an API to register an application and a system message to notify the application to restart. Other work needs to be implemented by our developers, this may disappoint us a bit, but it is understandable, because the system does not know the program status is important and must be restored; these should be the responsibility of developers. There are also two important points. When restarting the manager, we must note that: 1) the restart manager API is available only in kernel32.dll of Vista, therefore, if your application needs to provide support, it must be compiled on Vista; 2) to ensure that our application can run normally on xp and the system, check the system version before calling RegisterApplicationRestart, for example, Environment. osVersion or GetVersionEx API is called only when the version is later than 6.0.6000. Otherwise, a crash occurs. Resource:1) restart the manager demo, restartmanagercontroller, restartmanagerlistner (send me a mail if needed) 2) msdn documentation: http://msdn.microsoft.com/windowsvista
/Prodinfo/what/reliability/default. aspx

 

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.