472,142 Members | 1,293 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

Detect Shutdown from .NET

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
6 9220
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
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
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
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
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
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.

Similar topics

2 posts views Thread by Austin | last post: by
2 posts views Thread by Austin | last post: by
2 posts views Thread by Mike Stephens | last post: by
1 post views Thread by Jerry Camel | last post: by
6 posts views Thread by Adnan Hebibovic | last post: by
13 posts views Thread by Shailesh Humbad | last post: by
4 posts views Thread by Chris Johnson | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.