Giter VIP home page Giter VIP logo

zombifyme's Introduction

Zombify Me

Build status CodeFactor codecov

A library that can restart the program it's linked with if it crashes unexpectedly.

To use it, just include ZombifyMe.dll as a reference in your project and add the following code.

Process startup

At startup, after initialization completed successfully, enable ZombifyMe.

Zombification Zombification = new Zombification("My unique name");
Zombification.ZombifyMe();

At this point, if the process crashes, it will be automatiquely restarted.

Process exit

When you know the process is going to exit normally, whether it's reporting success or an error, cancel the watcher:

Zombification.Cancel();

Restarted process

A program can know if it has been started normally, or restarted, by reading the static property Zombification.IsRestart. Note that this value is set only if the NoWindow flag was set (see below).

Parameters

  • The name provided in the constructor just needs to be unique vs other users of ZombifyMe. A simple string such as your product name or a guid is enough. Avoid special characters that have a meaning or are forbidden in file and directory names.
  • Change the Delay property to add a delay before the process is restarted (accuracy is about 10 seconds).
Zombification.Delay = TimeSpan.FromMinutes(1);
  • You can customize some messages:
    • The message when watching over the process begins is set by the WatchingMessage property. The default message is null (no message).
    • The message when a process has been restarted is set in the RestartMessage property.
  • How the process is restarted can be controlled with some flags:
    • NoWindow: the new process is created with no window.
    • ForwardArguments (ON by default): arguments of the original process are reused when starting the new process.
  • You can enable symmetric monitoring setting IsSymmetric to true. When enabled, the original process and the process that monitors it watch over each other: if one is killed or crashes the other restarts it. When this is enabled it becomes quite difficult to manually kill any of these processes, so setting a large delay such as one minute is recommended.
  • In case IsSymmetric is set, symmetric monitoring could prevent the crash of the original process because there is still a thread alive: the monitoring thread. To prevent this unexpected side effect, it is recommended to set AliveTimeout to a non-zero value and call SetAlive regularly. If SetAlive is not called, the monitoring thread will exit, allowing the process to exit prematurely so it can be restarted. Calling SetAlive while IsSymmetric is false or AliveTimeout is zero has no effect.

The following example sets all parameters to their default value.

Zombification.Delay = TimeSpan.Zero;
Zombification.WatchingMessage = null;
Zombification.RestartMessage = "ZombifyMe Alert:\nA protected process has been restarted";
Zombification.Flags = Flags.ForwardArguments;
Zombification.IsSymmetric = false;
Zombification.AliveTimeout = TimeSpan.Zero;

zombifyme's People

Contributors

dlebansais avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.