我正在使用Topshelf与FluentSchedule结合使用Windows服务.
但是,我希望能够试运行应用程序只是启动而不执行设置计时器等的FluentSchedule代码.
有没有办法从命令行运行exe文件(即没有'install'命令)从TopShelf检查它是否在控制台模式下运行?
Chr*_*son 16
这有点像黑客,但你可以尝试将HostControl接口转换为ConsoleRunHost,如果是那种类型,你就是作为控制台应用程序运行.
当然,这并不理想,但你肯定可以在扩展方法中隐藏它,以减少它的难度.
public static bool IsRunningAsConsole(this HostControl control)
{
return control is ConsoleRunHost;
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以通过在服务配置中调用WhenStarted()来访问HostControl.
s.WhenStarted((tc, hostControl) => tc.Start(hostControl));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4105 次 |
| 最近记录: |