The Restart and recovery API
My programs do not crash, and I am sure about it. But if it is going happen is that an application "crashes", or simply not doing what is expected of it, then you can now be done with style and an automatic restart of the application. This helps the restart-and-recovery API that already introduced in Windows Vista and now Windows 7 has been extended. I have tried number of ways to solve it, but not succeeded in doing it. :no: So thought that some genius hanging out there will definitely help me. Please provide some notes that can be useful in resolving that quandary. Also provide some codes so that it can be useful for me to understand.
Re: The Restart and recovery API
The application simply not responding and all data is lost. Perhaps they have seen before, that some applications offer after a crash, right again to restart. And in the boot process then the lost data be recovered. Users of such applications are lucky. In such scenarios, you will have to try to register the application for a restart.
private void RegisterForRestart ()
{
ApplicationRestartRecoveryManager.RegisterForApplicationRestart (
new restart settings ("/ restart",
RestartRestrictions.NotOnReboot | RestartRestrictions.NotOnPatch));
}
Re: The Restart and recovery API
Also, i would like to suggest you to register the application for the recovery of data. The following are some codes that can be useful for you :
Code:
private void RegisterForRecovery ()
{
recovery data recovery data = new data (new recovery callback (recovery procedure), null);
recovery settings settings = new recovery settings (data, 0);
ApplicationRestartRecoveryManager.RegisterForApplicationRecovery (settings);
}
And then while implementing Recovery Method:
Code:
{
PingSystem ();
File.WriteAllText (recovery file string.Format ("{0} {1} {2} {0} {3}", DataSeparatorString, CurrentFile.Filename, CurrentFile.IsDirty, CurrentFile.Contents));
Debug.WriteLine ("File path:" + file recovery);
Debug.WriteLine ("File exists:" + File.Exists (file recovery));
Debug.WriteLine ("Application shutting down ...");
ApplicationRestartRecoveryManager.ApplicationRecoveryFinished (true);
return 0;
}
Re: The Restart and recovery API
Reboot to restore the data. The following are some codings that will be useful for you while restarting your API.
Code:
private void recover last session (string command)
{
if (File.Exists (file recovery))
{
MessageBox.Show (this, string.Format ("{0} file does not exist Recovery" recovery file));
internalLoad = true;
textBox1.Text = "not recover the data. Could recovery data file does not exist";
internalLoad = false;
UpdateAppTitle ();
Return;
}
// Perform application state restoration actions here.
string contents = File.ReadAllText (recovery file);
CurrentFile.Filename = contents.Remove (contents.indexOf (Form1.DataSeparatorString));
contents = contents.Remove (0 contents.indexOf (Form1.DataSeparatorString) +
Form1.DataSeparatorString.Length);
CurrentFile.IsDirty = contents.Remove (contents.indexOf (Form1.DataSeparatorString)) == "true"? true: false;
contents = contents.Remove (0 contents.indexOf (Form1.DataSeparatorString) + Form1.DataSeparatorString.Length);
CurrentFile.Contents = contents;
// Load our textbox
textBox1.Text = CurrentFile.Contents;
/ Update the title
UpdateAppTitle ();
// Reset our variable to next title updates we do not show the "recovered" text
recovered = false;
}