computer reset of Power off

  • Thread starter Thread starter PiotrKolodziej
  • Start date Start date
P

PiotrKolodziej

Hi
When my application is on, i can't reset or power off computer. Every
program closes but this one....
Why this happens?
PK
 
|
| Hi
| When my application is on, i can't reset or power off computer. Every
| program closes but this one....
| Why this happens?
| PK
|
|

My guess is that you have another foreground thread running next to the UI
thread. Make this one a background thread.
If you need this thread to clean-up, you'll have to register a
SystemEvents.SessionEnding event handler, but make sure you read the remarks
in SystemEvents.SessionEnding Event in MSDN.

Willy.
 
My guess is that you have another foreground thread running next to the UI
thread. Make this one a background thread.
If you need this thread to clean-up, you'll have to register a
SystemEvents.SessionEnding event handler, but make sure you read the
remarks
in SystemEvents.SessionEnding Event in MSDN.

Willy.

I should give more info - Sorry.
This happens because iam canceling the Close event such that user is not
closing app when X button was clicked.
I tryied to add Environment.HasShutdownStarted but it not works. When i
disable e.Cancel = true, windows is closing normally.
Have any idea how to bite this?
PK

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
this.Visible = false;
this.activated = false;
this.WindowState = FormWindowState.Minimized;

if (!Environment.HasShutdownStarted)
{
// Cancel the close...
e.Cancel = true;
}
}
 
|
| > My guess is that you have another foreground thread running next to the
UI
| > thread. Make this one a background thread.
| > If you need this thread to clean-up, you'll have to register a
| > SystemEvents.SessionEnding event handler, but make sure you read the
| > remarks
| > in SystemEvents.SessionEnding Event in MSDN.
| >
| > Willy.
|
| I should give more info - Sorry.
| This happens because iam canceling the Close event such that user is not
| closing app when X button was clicked.
| I tryied to add Environment.HasShutdownStarted but it not works. When i
| disable e.Cancel = true, windows is closing normally.
| Have any idea how to bite this?
| PK
|
| private void Form1_Closing(object sender,
| System.ComponentModel.CancelEventArgs e)
| {
| this.Visible = false;
| this.activated = false;
| this.WindowState = FormWindowState.Minimized;
|
| if (!Environment.HasShutdownStarted)
| {
| // Cancel the close...
| e.Cancel = true;
| }
| }
|
|

By setting e.Cancel to true, you prevent windows to close the form and as
such the application.
You should set e.Cancel to false is you accept to close.

Willy.
 
By setting e.Cancel to true, you prevent windows to close the form and as
such the application.
You should set e.Cancel to false is you accept to close.

I dont have to. e.Cancel is false by the default. Anyway
Environment.HasShutdownStarted isn't true even if iam closing windows. How
do i detect that windows is shutting down in other way...
 
|> By setting e.Cancel to true, you prevent windows to close the form and as
| > such the application.
| > You should set e.Cancel to false is you accept to close.
| >
|
| I dont have to. e.Cancel is false by the default. Anyway
| Environment.HasShutdownStarted isn't true even if iam closing windows. How
| do i detect that windows is shutting down in other way...
|
|

This is one of the way's to detect a "system shutdown", another way is to
register a handler for the SystemEvents.SessionEnding and/or SessionEnded
events.

However, in the subject line you state "reset of power off", if you mean by
this, pushing the reset or power button, it will depend how the system is
configured what action will follow.
A reset will in general stop the system cold, pushing the power button will
execute whatever was set in the power options (hibernate, standby,
shutdown...).

Willy.
 
However, in the subject line you state "reset of power off", if you mean
by
this, pushing the reset or power button, it will depend how the system is
configured what action will follow.
A reset will in general stop the system cold, pushing the power button
will
execute whatever was set in the power options (hibernate, standby,
shutdown...).

Willy.

Thank you.
I registred an event that you were talking about.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top