By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,054 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,054 IT Pros & Developers. It's quick & easy.

computer reset of Power off

P: n/a

Hi
When my application is on, i can't reset or power off computer. Every
program closes but this one....
Why this happens?
PK
Sep 28 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"PiotrKolodziej" <pi*************@gmail.comwrote in message
news:e3***************************@news.chello.pl. ..
|
| 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.

Sep 28 '06 #2

P: n/a
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;
}
}
Sep 28 '06 #3

P: n/a

"PiotrKolodziej" <pi*************@gmail.comwrote in message
news:28***************************@news.chello.pl. ..
|
| 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.

Sep 28 '06 #4

P: n/a
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...
Sep 28 '06 #5

P: n/a

"PiotrKolodziej" <pi*************@gmail.comwrote in message
news:1b**************************@news.chello.pl.. .
|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.
Sep 28 '06 #6

P: n/a
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.
Sep 29 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.