|
-
May 19th, 2011, 11:20 AM
#1
is there a way to "save" the state of the program if it's abruptly terminated?
I have a console program that will be running in the background (to monitor changes in directories, then query database, etc, then sends email when there's a problem - based on the records that are saved/or not saved in the DB)..
I have counters, boolean values, etc that I maintain and use within the code as I progress from one line to another..
Now, I was asked - Can I make this program to "recover" if the program is "accidentally" terminated and opened again?
I was thinking of: when the console program is closed, I save all the variables, etc from a .txt file and when it starts up, it looks for that .txt file and get all the counters from there.
Is there any other way of doing this?
-
May 19th, 2011, 12:43 PM
#2
Re: is there a way to "save" the state of the program if it's abruptly terminated?
I have a monitoring program that does that. It uses a flat text file to save some temp data to. It will read this temp file before it starts processing again.
The only problem is that if the program is terminated during the writing of this file it might not resume correctly. The chances are pretty low but still a risk. Maybe someone knows of something built into .NET to handle this.
-
May 19th, 2011, 02:53 PM
#3
Re: is there a way to "save" the state of the program if it's abruptly terminated?
my program is a console application.. how to know when a console application is closed/terminated/exit, etc? do i have to have another console app that monitors this (other) console app?
user612345 = how did you detect the termination of the console app? would you share the code? thanks in advance..
-
May 19th, 2011, 03:10 PM
#4
Re: is there a way to "save" the state of the program if it's abruptly terminated?
Here is an article about detecting closing console application...
http://social.msdn.microsoft.com/for...-62a1eddb3c4a/
-
May 19th, 2011, 03:33 PM
#5
Re: is there a way to "save" the state of the program if it's abruptly terminated?
And for the sake of the original question posed... I would create a small serializable class to store the data you want to recover, provides a nice clean way to write / read XML file rather than plain text.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|