SelfKeeper 1.0.0-beta-005
This is a prerelease version of SelfKeeper.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SelfKeeper --version 1.0.0-beta-005
NuGet\Install-Package SelfKeeper -Version 1.0.0-beta-005
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-005" />
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-005
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SelfKeeper, 1.0.0-beta-005"
#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-005&prerelease // Install SelfKeeper as a Cake Tool #tool nuget:?package=SelfKeeper&version=1.0.0-beta-005&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SelfKeeper
1. Intro
A library that lets applications run as their own watchdog.
允许应用程序作为自己的看门狗运行的库。
- 支持部分信号传递到工作进程,可以在某些情况下执行优雅关闭;
- 原始的控制台输出颜色会被保留;
工作原理
通过命令行参数判断当前是否是工作进程,如果不是,则复制当前进程的启动设置,添加相关命令行参数后启动工作进程,并监控其运行状态。
关键词
- 工作进程(Worker Process): 运行程序实际逻辑的进程
- 主进程(Host Process): 启动并监控工作进程的进程
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.WorkerProcessOptionsCommandArgumentName = "--worker-process-options"; //自定义工作进程选项的参数名
options.NoKeepSelfCommandArgumentName = "--no-keep-self"; //自定义不启用 KeepSelf 的参数名
options.NoKeepSelfEnvironmentVariableName = "NoWatchDog"; //自定义不启用 KeepSelf 的环境变量名
});
- 主进程会在
KeepSelf.Handle
阻塞,启动并监控工作进程; - 主进程在退出时会在
KeepSelf.Handle
内调用Environment.Exit
退出,不会执行后面的代码;
Product | Versions 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 | 23,512 | 1/7/2024 |
1.1.0 | 28,092 | 2/4/2023 |
1.0.0 | 7,183 | 7/3/2022 |
1.0.0-beta-005 | 242 | 5/13/2022 |
1.0.0-beta-004 | 169 | 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 |