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 ();}