SelfKeeper 1.0.0-beta-004

This is a prerelease version of SelfKeeper.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SelfKeeper --version 1.0.0-beta-004                
NuGet\Install-Package SelfKeeper -Version 1.0.0-beta-004                
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="SelfKeeper" Version="1.0.0-beta-004" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SelfKeeper --version 1.0.0-beta-004                
#r "nuget: SelfKeeper, 1.0.0-beta-004"                
#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 SelfKeeper as a Cake Addin
#addin nuget:?package=SelfKeeper&version=1.0.0-beta-004&prerelease

// Install SelfKeeper as a Cake Tool
#tool nuget:?package=SelfKeeper&version=1.0.0-beta-004&prerelease                

SelfKeeper

1. Intro

A library that lets applications run as their own watchdog.

允许应用程序作为自己的看门狗运行的库。


  • 支持部分信号传递到子进程,可以在某些情况下执行优雅关闭;
  • 原始的控制台输出颜色会被保留;

工作原理

通过命令行参数判断当前是否是子进程,如果不是,则复制当前进程的启动设置,添加相关命令行参数后启动子进程,并监控其运行状态。

2. 如何使用

2.1 安装Nuget

dotnet add package SelfKeeper --prerelease

2.2 启用SelfKeeper

在程序入口处添加处理代码

KeepSelf.Handle(args);

或进行更多配置

KeepSelf.Handle(args, options =>
{
    options.RemoveFlag(KeepSelfFeatureFlag.SkipWhenDebuggerAttached | KeepSelfFeatureFlag.DisableForceKillByHost);   //配置功能
    options.StartFailRetryDelay = TimeSpan.FromSeconds(1);  //配置启动失败的重试延时
    options.RestartDelay = TimeSpan.FromSeconds(1); //进程退出后的重启延时
    options.Logger = null;  //配置日志记录器
    options.ChildProcessOptionsCommandArgumentName = "--child-process-options"; //自定义子进程选项的参数名
    options.NoKeepSelfCommandArgumentName = "--no-keep-self"; //自定义不启用 KeepSelf 的参数名
    options.NoKeepSelfEnvironmentVariableName = "NoWatchDog"; //自定义不启用 KeepSelf 的环境变量名
});
  • 主进程会在 KeepSelf.Handle 阻塞,启动并监控子进程;
  • 主进程在退出时会在 KeepSelf.Handle 内调用 Environment.Exit 退出,不会执行后面的代码;
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.1.1 26,384 1/7/2024
1.1.0 28,094 2/4/2023
1.0.0 7,187 7/3/2022
1.0.0-beta-005 244 5/13/2022
1.0.0-beta-004 171 5/11/2022
1.0.0-beta-003 175 5/9/2022
1.0.0-beta-002 169 5/8/2022
1.0.0-beta-001 190 5/6/2022