Detecting Shutdown.exe

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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.
 
Shutdown will close your program. Simply set your program to save all its
data when it closes.
 
cashdeskmac said:
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
 
J. Buelna - Houston said:
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
 
J. Buelna - Houston said:
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
 
Back
Top