Click here to Skip to main content
16,003,423 members
Home / Discussions / C#
   

C#

 
GeneralRe: mainly p.s. Pin
exhaulted20-Sep-04 5:17
exhaulted20-Sep-04 5:17 
GeneralRe: Form.Close() Pin
Salil Khedkar20-Sep-04 2:10
Salil Khedkar20-Sep-04 2:10 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 3:15
exhaulted20-Sep-04 3:15 
GeneralRe: Form.Close() Pin
Heath Stewart20-Sep-04 6:55
protectorHeath Stewart20-Sep-04 6:55 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 22:22
exhaulted20-Sep-04 22:22 
GeneralRe: Form.Close() Pin
Salil Khedkar20-Sep-04 23:30
Salil Khedkar20-Sep-04 23:30 
GeneralRe: Form.Close() Pin
exhaulted21-Sep-04 4:11
exhaulted21-Sep-04 4:11 
GeneralRe: Form.Close() Pin
Heath Stewart21-Sep-04 5:28
protectorHeath Stewart21-Sep-04 5:28 
No, Application.Exit doesn't fire the Form.Closing event, nor should it. Calling Application.Exit is the same as sending WM_QUIT to your message pump. When you close a form, you're essentially sending WM_CLOSE.

The fact that the events happen in the wrong order means you're not doing something right. You add a handler for the SystemEvents.SessionEnding in your form's instance (not in Main - your default entry point - since Application.Run is a blocking call). Set a flag then call Close. This sends WM_CLOSE to your window proc and your Closing event handler is called.

The previous post is correct then, and recommended was I was going to: use state variables. A simple bool would do.

The SystemEvents.SessionEnding event (not to be confused with SystemEvents.SessionEnded; if that's fired there's nothing you can do, really, at least as far as prompting for user input) handles the WM_QUERYENDSESSION message which is sent to application message pumps. This has nothing to do with WM_CLOSE or WM_QUIT. It simply notifies the window proc that a request to end the interactive session has been posted.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: Form.Close() Pin
exhaulted21-Sep-04 6:23
exhaulted21-Sep-04 6:23 
GeneralRe: Form.Close() Pin
Heath Stewart21-Sep-04 6:37
protectorHeath Stewart21-Sep-04 6:37 
GeneralRe: Form.Close() Pin
exhaulted21-Sep-04 22:44
exhaulted21-Sep-04 22:44 
GeneralRe: Form.Close() Pin
Heath Stewart22-Sep-04 6:57
protectorHeath Stewart22-Sep-04 6:57 
GeneralRe: Form.Close() Pin
yoaz20-Sep-04 2:56
yoaz20-Sep-04 2:56 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 3:10
exhaulted20-Sep-04 3:10 
GeneralRe: Form.Close() Pin
Nicholas Cardi20-Sep-04 4:50
Nicholas Cardi20-Sep-04 4:50 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 6:16
exhaulted20-Sep-04 6:16 
GeneralRe: Form.Close() Pin
Nicholas Cardi20-Sep-04 7:59
Nicholas Cardi20-Sep-04 7:59 
GeneralRe: Form.Close() Pin
Nicholas Cardi20-Sep-04 8:07
Nicholas Cardi20-Sep-04 8:07 
GeneralData Table From DataRow[] Pin
sreejith ss nair19-Sep-04 22:50
sreejith ss nair19-Sep-04 22:50 
GeneralRe: Data Table From DataRow[] Pin
Sendilkumar.M20-Sep-04 1:52
Sendilkumar.M20-Sep-04 1:52 
GeneralRe: Data Table From DataRow[] Pin
sreejith ss nair20-Sep-04 17:35
sreejith ss nair20-Sep-04 17:35 
GeneralRe: Data Table From DataRow[] Pin
Sendilkumar.M20-Sep-04 18:27
Sendilkumar.M20-Sep-04 18:27 
Generalmultiple selection in datagrid Pin
Sudee19-Sep-04 19:47
Sudee19-Sep-04 19:47 
GeneralRe: multiple selection in datagrid Pin
sreejith ss nair19-Sep-04 20:27
sreejith ss nair19-Sep-04 20:27 
GeneralRe: multiple selection in datagrid Pin
Sudee19-Sep-04 21:15
Sudee19-Sep-04 21:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.