Click here to Skip to main content
15,912,578 members
Home / Discussions / C#
   

C#

 
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 
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 
Again, you should call Close in your SystemEvents.SessionEnding event handler, after setting the state variable.

The problem is that canceling the WM_CLOSING notification message (setting CancelEventArgs.Cancel to true in your Form.ClosingEvent) won't affect the WM_QUERYENDSESSION notification message (your SystemEvents.SessionEnding handler). I would recommend implementing the same logic into both handlers:
private void OnSessionEnding(object sender, SessionEndingEventArgs e)
{
  e.Cancel = !CheckPassword();
}
The big problem here is that prompting the user takes time (mostly for the user to type their password, unless you're authenticating the password across some wire format or against a slow database; hardcoding it into the assembly is a bad idea since even a tool that comes with the free SDK can read it easily) - more time than Windows is willing to give it when shutting down. The application will appear hung and the user will be prompted to end the task (process) or cancel the shutdown. Inevitably, the user will blame your program.

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 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 
GeneralRe: multiple selection in datagrid Pin
sreejith ss nair19-Sep-04 21:35
sreejith ss nair19-Sep-04 21:35 
GeneralRe: multiple selection in datagrid Pin
Sudee19-Sep-04 23:28
Sudee19-Sep-04 23:28 

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.