Abraham.AutoRecovery 1.0.2

dotnet add package Abraham.AutoRecovery --version 1.0.2
NuGet\Install-Package Abraham.AutoRecovery -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Abraham.AutoRecovery" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Abraham.AutoRecovery --version 1.0.2
#r "nuget: Abraham.AutoRecovery, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Abraham.AutoRecovery as a Cake Addin
#addin nuget:?package=Abraham.AutoRecovery&version=1.0.2

// Install Abraham.AutoRecovery as a Cake Tool
#tool nuget:?package=Abraham.AutoRecovery&version=1.0.2

Abraham.AutoRecovery

Abstract

This library provides a scheduler for automatically saving user data and a supervisor process to automatically restart your app after a crash.

License

Licensed under Apache licence. https://www.apache.org/licenses/LICENSE-2.0

Compatibility

The nuget package was build with DotNET 6.

Example

For an example refer to project "AutoRecoveryDemoWPF". It demonstrates both features:

  1. The scheduler that triggers a given function periodically to save the user's data.
  2. When you app starts, a separate (hidden) process is started to monitor your app. In case you app crashes and its process ends, the hidden process will restart your app. If your process ends normally, the hidden process will also end.

Getting started

Add the Nuget package "Abraham.AutoRecovery" to your project.

Add a field to your project:

		IAutoRecovery _autoRecovery = new AutoRecovery();

Adding AutoSave to your project

At startup of your app, add the following code:

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			if (_autoRecovery.AppHasCrashed)
				LoadDataFromAutoSaveFile();
			else
				LoadData();
			_autoRecovery.EnableAutoSave(10, SaveDataForAutoSave); // save every 10 seconds
		}

This method will be called periodically to save the user's data:

		private void SaveDataForAutoSave()
		{
			Dispatcher.Invoke(() => { SaveDataToAutoSaveFile(); });
		}

At shutdown, add the following code:

		private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			SaveData();
			DeleteAutoSaveFile(); // optional
		}

After saving user's data as usual, you can add a method that deletes the file containing the autosave data.

Adding AutoRestart to your project

At startup of your app, add the following code. (You'll want to change startVisible to false after verifying it's working):

		private void Window_Loaded(object sender, RoutedEventArgs e)
		{
			_autoRecovery.EnableAutoRestart(startVisible: true); // restart this app after crash, start visible for Demo only!
		}

At shutdown, add the following code:

		private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			_autoRecovery.NormalShutdown();
		}

This call will end the hidden supervisor process.

Testing AutoRestart

  • Start the demo app 'AutoRecoveryDemoWPF.exe' by doubleclicking.
  • The go to task manager and end this process.
  • Don't kill process tree! Only kill the single process.
  • After a few seconds the supervisor process will recognize that and restart your process.

HOW TO INSTALL A NUGET PACKAGE

This is very simple:

  • Start Visual Studio (with NuGet installed)
  • Right-click on your project's References and choose "Manage NuGet Packages..."
  • Choose Online category from the left
  • Enter the name of the nuget package to the top right search and hit enter
  • Choose your package from search results and hit install
  • Done!

or from NuGet Command-Line:

Install-Package Abraham.ProgramSettingsManager

AUTHOR

Oliver Abraham, mail@oliver-abraham.de, https://www.oliver-abraham.de

Please feel free to comment and suggest improvements!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 249 11/11/2023
1.0.1 412 6/12/2022
1.0.0 282 1/2/2022

Included debug symbols