473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 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 9400
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Austin | last post by:
I wrote a program running on windows. I put the link of the program in "Start up" folder and let it executed minimized. Every time when I open the computer, my program will be running in system...
2
by: Austin | last post by:
My program is running on windows and it is wrritten by Python and wxPython, built by py2exe. If my program is executed minimized, and the user want to shutdown or reboot. Meanwhile, my program...
0
by: Will Haney | last post by:
I have a .NET application that needs to perform some last moment duties upon termination. The application has no forms with one Module containing the Sub Main. How can I detect/trap the...
2
by: Mike Stephens | last post by:
I have an application to minimizes when X is clicked. If the user wants to close the application they click the Exit Application button.This works fine and does exactly what I need. I have since...
1
by: Jerry Camel | last post by:
How do you detect when a system is being logged off or shutdown? In VB 6 there was a QueryUnload event that would work if you had a form, but I'm running in a Sub Main scenario... I can't find...
12
by: Patrick Dugan | last post by:
I have an vb.net application that is a module that uses a "application.run" in the sub main to start. There is no form involved (just a system tray icon) How can you detect when the application...
6
by: Adnan Hebibovic | last post by:
Hello developers How can I detect Windows shutdown from .NET and I mean clean .NET not catching the events with Win32 API ... Thanks
13
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record...
4
by: Chris Johnson | last post by:
Hey all, I have a small app I have developed that periodically pings a list of server and returns their status. Given my environment I have setup the program such that a server can be down 4...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.