Click here to Skip to main content
16,018,202 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
OK I'm new to programming, so bear with me here, my program is in a 14 day loop C#
How would I go about saving the state within the program.
Like if the power went out, so it would start back up at the point it left off.
At 1st I was going to do this via hardware,backup battery.I thought this might be a lot of trouble doing it software,well it doesn't hurt to ask.
Posted

The problem with doing it in software is that if it takes any significant amount of time, there is a good chance that it will be executing when the power fails!

You can do something to recover your last state (crash Chrome for example, and it offers to reload your last displayed pages) all you have to do is make sure you write to a different file and do not remove the old one until the new one has been flushed to disk. Just be careful with your frequency of writes - applications which do this too often can be very, very annoying! (But ones which don't can be even worse - it's a fine balance).

If you need it properly safe, the an external UPS is a good idea - you can get them with a USB connection to trigger a mass-save-and-get-ready-to-die-cleanly event. They aren't that expensive, considering how much other hassle they can save you! You may even find they are cheaper than your time spent in adding the code and testing it...
 
Share this answer
 
Thanks just what I thought, although the program is simple that wont make it simple to make a backup program for it, better to do it via hardware.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900