Click here to Skip to main content
13,259,847 members (46,478 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


15 bookmarked
Posted 27 Nov 2011

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.


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


About the Author

Michael Haephrati
CEO Secured Globe, Inc.
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.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Barb Henry 213-Oct-12 12:27
memberBarb Henry 213-Oct-12 12:27 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 16 Feb 2013
Article Copyright 2011 by Michael Haephrati
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid