473,503 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting Shutdown.exe

I want to detect when the users computer is going to close down so that I can
write all unfinished data to a file before closing down. Does anyone know
how this is done?
Nov 17 '05 #1
5 2216
What unfinished data are you talking about? You mean stuff that your own
application uses, or other applications.

There probably are ways of hooking the shutdown event, but could you just do
that when your program closes? If you are monitoring other applications,
then you might create like a Windows service or a NotifyIcon class that just
sites around waiting for some event to terminate their process, then save
all your data.

"cashdeskmac" <ca*********@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
I want to detect when the users computer is going to close down so that I can write all unfinished data to a file before closing down. Does anyone know
how this is done?

Nov 17 '05 #2
Shutdown will close your program. Simply set your program to save all its
data when it closes.

"cashdeskmac" <ca*********@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
I want to detect when the users computer is going to close down so that I
can
write all unfinished data to a file before closing down. Does anyone know
how this is done?

Nov 17 '05 #3

"cashdeskmac" <ca*********@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
I want to detect when the users computer is going to close down so that I
can
write all unfinished data to a file before closing down. Does anyone know
how this is done?

Hello cashdeskmac,

Here's how I've done it in the past.

Create a class with a static constructor that will hold a Check.IsSaved
property:

public Check
{
static Check() {}

private string _isSaved = "";
public bool IsSaved
{
set { _isSaved = value; }
get { return _isSaved; }
}
// other static check values...
}

Whenever data has changed, change the IsSaved property to false.
Whenever a file is saved, change the IsSaved status to true.
Finally, check the IsSaved property when the application is about to close
and take the appropriate action/inaction.

Handlers on component and application events will make this a snap.

J. Buelna - Houston, TX


Nov 17 '05 #4

"J. Buelna - Houston, TX" <jbuelna-not@microsoft...yet.com> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...

"cashdeskmac" <ca*********@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
I want to detect when the users computer is going to close down so that I
can
write all unfinished data to a file before closing down. Does anyone
know
how this is done?

Hello cashdeskmac,

Here's how I've done it in the past.

Create a class with a static constructor that will hold a Check.IsSaved
property:

public Check
{
static Check() {}

private string _isSaved = "";
public bool IsSaved
{
set { _isSaved = value; }
get { return _isSaved; }
}
// other static check values...
}

Whenever data has changed, change the IsSaved property to false.
Whenever a file is saved, change the IsSaved status to true.
Finally, check the IsSaved property when the application is about to
close and take the appropriate action/inaction.

Handlers on component and application events will make this a snap.

J. Buelna - Houston, TX

I initially intended to make a string property called Check.SaveStatus, but
instead went with a bool and forgot to change the type of the private field.
It should be:

private bool _isSaved = "";

J. Buelna - Houston, TX

Nov 17 '05 #5

"J. Buelna - Houston, TX" <jbuelna-not@microsoft...yet.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...

"J. Buelna - Houston, TX" <jbuelna-not@microsoft...yet.com> wrote in
message news:e%****************@tk2msftngp13.phx.gbl...

"cashdeskmac" <ca*********@discussions.microsoft.com> wrote in message
news:9B**********************************@microsof t.com...
I want to detect when the users computer is going to close down so that I
can
write all unfinished data to a file before closing down. Does anyone
know
how this is done?

Hello cashdeskmac,

Here's how I've done it in the past.

Create a class with a static constructor that will hold a Check.IsSaved
property:

public Check
{
static Check() {}

private string _isSaved = "";
public bool IsSaved
{
set { _isSaved = value; }
get { return _isSaved; }
}
// other static check values...
}

Whenever data has changed, change the IsSaved property to false.
Whenever a file is saved, change the IsSaved status to true.
Finally, check the IsSaved property when the application is about to
close and take the appropriate action/inaction.

Handlers on component and application events will make this a snap.

J. Buelna - Houston, TX

I initially intended to make a string property called Check.SaveStatus,
but instead went with a bool and forgot to change the type of the private
field. It should be:

private bool _isSaved = "";

J. Buelna - Houston, TX

Der!!!!!!!!!!!!!!

private bool _isSaved = true; // assume that when the class is
initialized, no data has been entered.
J. Buelna - Houston, TX

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7547
by: Tim Gosselin | last post by:
I am writing a tcp tunnel but cannot find a way of detecting when a socket shuts down its read end without writing to the socket. For testing the write end of the remote endpoint I just do a: if...
6
18455
by: Michael Kennedy [UB] | last post by:
Hi, I have a project using the TcpClient and its associated NetworkStream. Everything works well except for one condition which I haven't found any information about dealing with: How do I...
5
3693
by: Rich | last post by:
I have a simple, single threaded program in C++ that runs as Idle priority. The program creates some data which needs dumping to file if the computer is shutdown or logged out. At the moment...
8
2994
by: Les Desser | last post by:
Is there any way to detect within A97 when Windows is trying to shut down, so I can close down the application gracefully? We currently have a trap in the main menu asking the user to confirm if...
6
16622
by: Bruce Vander Werf | last post by:
I am using the asynchronous send/receive methods of the Socket class. When the remote end closes the socket, the callback for receive is called and EndReceive returns 0. Socket.Connected still...
5
14660
by: David Griffin | last post by:
I have a console application that spawns off several C# threads. It needs to react to shutdown of the system by performing some end of program activities including writing some files and closing...
2
2304
by: Paul Steele | last post by:
Some time ago I tracked down the code for detecting the shutdown event within a C# program. I tested it, it worked, and I moved on. However, I just discovered that the code is no longer working,...
0
1135
by: Jerry Camel | last post by:
Using SessionEnding, I can determine if the users session is ending via logoff or shutdown, but it doesn't differentiate between shutdown and restart... Shutdown and Restart both show the same...
0
1113
by: sam | last post by:
I have a vb.net app that runs without a visible window. When the user logs off or attempts a shutdown, the app is not quitting and prevents the logoff/shutdown until the task is killed. Is there...
0
1132
by: =?Utf-8?B?SiBTdHJlZ2Vy?= | last post by:
I am using C#.NET 2003, and my form has a WndProc override to capture the windows messages. I can halt the shutdown the user initiated and run my code, but I wanted to see if there was a way to...
0
7205
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
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7467
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
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.