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

Detect Shutdown from .NET

P: n/a
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks
Jul 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Try handling the Microsoft.Win32.SessionEnded event.

"Adnan Hebibovic" wrote:
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks

Jul 21 '05 #2

P: n/a
When the form is minimized to systray there is no Win32.SessionEnded event
....

Thanks
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
Try handling the Microsoft.Win32.SessionEnded event.

"Adnan Hebibovic" wrote:
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks

Jul 21 '05 #3

P: n/a
Your first post asked how to "detect Windows shutdown". My response answered
that. I just tried it out, and it worked (although I used session ending
vice session ended). I run my program, I try to shut down windows, and the
event fires. Your second post asks about minimizing. For that, you should
handle the form's resize event and check the form property WindowState. If
it is FormWindowState.Minimized, then the window is minimized.

Windows shutdown and minimizing a window are different things. What exactly
are you trying to detect?

"Adnan Hebibovic" wrote:
When the form is minimized to systray there is no Win32.SessionEnded event
....

Thanks
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
Try handling the Microsoft.Win32.SessionEnded event.

"Adnan Hebibovic" wrote:
Hello developers

How can I detect Windows shutdown from .NET and I mean clean .NET not
catching the events with Win32 API ...

Thanks


Jul 21 '05 #4

P: n/a
Hi,

I think Adnan might be asking that when he minimized a window to the system
tray, the SessionEnded event is not fired. Right?

I have tried it on my machine, and it works fine under any circumstances.
Please try my code in a new windows application.

private void Form1_Load(object sender, System.EventArgs e)
{
Microsoft.Win32.SystemEvents.SessionEnded +=new
Microsoft.Win32.SessionEndedEventHandler(SystemEve nts_SessionEnded);
this.Resize +=new EventHandler(Form1_Resize);
}

private void SystemEvents_SessionEnded(object sender,
Microsoft.Win32.SessionEndedEventArgs e)
{
MessageBox.Show("End");
}

private void Form1_Resize(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.notifyIcon1.Visible=true;
}
else
this.ShowInTaskbar = true;
this.notifyIcon1.DoubleClick+=new EventHandler(notifyIcon1_DoubleClick);
}

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}

HTH.

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

Jul 21 '05 #5

P: n/a
Thanks I see now where is the problem with my code.

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:PP**************@TK2MSFTNGXA03.phx.gbl...
Hi,

I think Adnan might be asking that when he minimized a window to the
system
tray, the SessionEnded event is not fired. Right?

I have tried it on my machine, and it works fine under any circumstances.
Please try my code in a new windows application.

private void Form1_Load(object sender, System.EventArgs e)
{
Microsoft.Win32.SystemEvents.SessionEnded +=new
Microsoft.Win32.SessionEndedEventHandler(SystemEve nts_SessionEnded);
this.Resize +=new EventHandler(Form1_Resize);
}

private void SystemEvents_SessionEnded(object sender,
Microsoft.Win32.SessionEndedEventArgs e)
{
MessageBox.Show("End");
}

private void Form1_Resize(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.notifyIcon1.Visible=true;
}
else
this.ShowInTaskbar = true;
this.notifyIcon1.DoubleClick+=new EventHandler(notifyIcon1_DoubleClick);
}

private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}

HTH.

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

Jul 21 '05 #6

P: n/a
You're welcome, Adnan.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

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

Jul 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.