Click here to Skip to main content
Click here to Skip to main content

Tagged as

Continuing from where you last stopped

, 15 Feb 2013
Rate this:
Please Sign up or sign in to vote.
Many types of applications must have the ability to recover from an abnormal termination and continue from where they stopped
Many types of applications must have the ability to recover from an abnormal termination and continue from where they stopped.
 
Among these applications, hard drive recovery, backup applications, data processing, etc., abnormal termination might be a computer reset, a crash or a human error. This tip is a conceptual and a generic tip, which basically says: save the current status of your work frequent enough, so no matter what, in case on an abnormal termination, you can make your software continue from where it stopped. This tip can be helpful in most cases. I have used it for many years, and it saved me a lot of time, especially with data processing applications, which processed 100,000+ records. It is true that one can always think of scenarios where a specific record or task will cause an unhandled error and the mechanism I am suggesting will recreate the same error again and again, but that can be solved with a proper error handling mechanism
 
There are two parts of a simple recovery mechanism:
  1. Constantly save the current state.
  2. Recover from an abnormal termination.

Saving the current state

In order to save the current state, we need to determine which information is sufficient to be able to continue an ongoing process. For example, if we go over a database and process each record, it would be sufficient to save the database details, table / recordset name and an index pointing to the current record processed. There is no need to save the data processed.

Where to save the current state

The best place to save such information would be the Registry. You create a set of keys for your application, and save the necessary data as part of the processing loop. Storing such data in the Registry is much faster than opening a data file and storing the data in such file.
Dim LastProcessedRecord As Integer
LastProcessedRecord = CurrentProcessedRecord
My.Computer.Registry.SetValue "HKEY_CURRENT_USER\Software\MyApp", "LastProcessedRecord",

How to distinguish between a normal and an abnormal termination

There is no point of having such a mechanism, unless we are able to activate the recovery mechanism only in cases of abnormal termination. To do so, we need to distinguish between these and the normal termination or completion of the task. To achieve that, we need to clear the "last processed record" key (or whatever name used for it) whenever the task is completed.

The Automatic Recovery

The idea is to automatically detect an abnormal termination last time the application ran, and in such case to pop-up a message to the user, asking him or her whether to continue from where the processing stopped last time. This message will not appear when the application is run for the first time, or when it completes its tasks as expected.
Dim LastProcessedRecord As Integer
LastProcessedRecord = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\
MyApp", "LastProcessedRecord", -1)
When automatic recovery is requested, the initial index is promoted to where it was last time, instead of starting from the first value assigned to it. So if the task involves processing records number 100 to 200, and last time the application crashed after reaching record 150, then next time, the index will start with 150 instead of 100.

License

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

Share

About the Author

Michael N. Haephrati
CEO
United States United States
Michael Haephrati, is an entrepreneur, inventor and a musician. Haephrati worked on many ventures starting from HarmonySoft, designing Rashumon, the first Graphical Multi-lingual word processor for Amiga computer. During 1995-1996 he worked as a Contractor with Apple at Cupertino. Worked at a research institute made the fist steps developing the credit scoring field in Israel. He founded Target Scoring and developed a credit scoring system named ThiS, based on geographical statistical data, participating VISA CAL, Isracard, Bank Leumi and Bank Discount (Target Scoring, being the VP Business Development of a large Israeli institute).

During 2000, he founded Target Eye, and developed the first remote PC surveillance and monitoring system, named Target Eye.

Other ventures included: Data Cleansing (as part of the DataTune system which was implemented in many organizations.


Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralRe: Could you be more specific? I will be more than happy to ame... PinmemberMichael Haephrati27-Dec-11 1:30 
GeneralReason for my vote of 4 Thanks for sharing the concept... it... Pinmember_DanO_6-Dec-11 4:06 
GeneralReason for my vote of 3 good tip Pinmembersudhansu_k1235-Dec-11 19:21 
GeneralVery nice article. Please help us further with some sample s... Pinmembersudhansu_k1235-Dec-11 19:20 
GeneralI agree with Reiss. You really only discuss how to write th... PinmemberKschuler28-Nov-11 6:35 
GeneralRe: The title is not misleading. This is a conceptual and a gene... PinmemberMichael Haephrati28-Nov-11 7:12 
GeneralYour title is misleading - your tip only illustrates how to ... PinmemberReiss27-Nov-11 23:32 
GeneralThanks man i was in so much need of this. hope it works for ... PinmemberJavedsamrt27-Nov-11 19:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 16 Feb 2013
Article Copyright 2011 by Michael N. Haephrati
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid