CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2011
    Posts
    54

    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?

  2. #2
    Join Date
    Jun 2010
    Posts
    56

    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.

  3. #3
    Join Date
    Apr 2011
    Posts
    54

    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..

  4. #4
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    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/

  5. #5
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    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
  •  





Click Here to Expand Forum to Full Width

Featured