Re: How do I intercept a close event?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Tinius (Tinius_at_discussions.microsoft.com)
Date: 01/13/05


Date: Thu, 13 Jan 2005 04:13:04 -0800

I cannot get Environment.HasShutdownStarted to work.
I placed it in;
private void MainForm_Closing(object sender,
 System.ComponentModel.CancelEventArgs e)

but it always returns false, even when shutting down WindowsXP prof.

I placed this MessageBox in the same routine;
MessageBox.Show(Environment.HasShutdownStarted.ToString(),"Shutting Down?");
which always returns FALSE.

I'm at a loss with how to differentiate between the User closing the app
down and Windows closing the app down

I even wrote a second very simple app and placed the
Environment.HasShutdownStarted in the form1_closing event. Still always
returns false.

I must be missing something obvious?

Tinius

"Greg Bacchus" wrote:

> One note on that though. You should first check if the computer is
> being shut down, otherwise the form will not automatically be closed
> and the computer will not turn off.
>
>
> private void MainForm_Closing(object sender,
> System.ComponentModel.CancelEventArgs e)
> {
> if( !Environment.HasShutdownStarted )
> {
> e.Cancel = true;
> this.Hide();
> }
> }
>
>



Relevant Pages

  • Threading woes
    ... and so I wrote a small test app to make sure ... private void startButton_Click(object sender, EventArgs e) ...
    (microsoft.public.dotnet.framework)
  • Event handling
    ... I am currently writing an app for a mobile phone. ... this, I have for example, a class that talks to the bluetooth device. ... private void CollectDataHandler ... sender and e are not valid here. ...
    (microsoft.public.dotnet.framework)
  • Problems with BackgroundWorker
    ... now i successfully added a BackgroundWorker to my App on a panel with: ... private void bgWorker_DoWork(object sender, DoWorkEventArgs e) ... work a little bit with the app, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiple forms problem
    ... private void button1_Click(object sender, System.EventArgs e) ... Of Course now you have to shutdown your app by yourself. ... could assign a Closed event to Form2 ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Threading problem
    ... Alvin Bruney ... private void goToolStripMenuItem_Click(object sender, EventArgs ... private void drawBitmap(BackgroundWorker worker, DoWorkEventArgs ... BackgroundWorker worker = sender as BackgroundWorker; ...
    (microsoft.public.dotnet.framework)