Reprinted the program written in C #. The system cannot be shut down because it cannot be exited during shutdown.

Source: Internet
Author: User

Original Site: http://q.cnblogs.com/q/9762/

 

C # The program written in C # cannot exit during shutdown, and the system cannot be shut down. 0 Reward garden beans:10 [Closed] Why is the problem closed? Browsing: 981 times

C # writtenProgramThe system cannot be shut down because it cannot exit during shutdown. My environment is Win XP and. NET Framework 2.0.

. NET technology accumulation | Beginner level 1 | Garden beans: 165
Question: Question added: Try to use: [stathread] Static void main (){................. systemevents. sessionending + = delegate {application. exit ();};..............} it seems that the shutdown event cannot be captured during Shutdown to find a solution: I wrote this program: There is a tray, there is a main form when the system is shut down, windows sends the wm_queryendsession message to each application. You can use E. closereason to obtain the formclosing event of the main form triggered by the message. I wrote e. Cancel = true; this. Hide (); In the event subscription method.Code, Done: If (E. closereason = closereason. applicationexitcall) | (E. closereason = closereason. windowsshutdown) {e. cancel = false; application. exit ();} else {e. cancel = true; this. hide ();}

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.