我想通过一些自定义参数的控制台应用程序,当我安装并启动它通过TopShelf Windows服务。
I want to pass some custom arguments to the console app when I install and start it as a Windows Service via TopShelf.
当我使用:
MyService install start /fooBar: Test
控制台应用程序失败:
Console application fails:
[失效]命令行一个未知的命令行选项,发现: DEFINE:Foobar的=测试
[Failure] Command Line An unknown command-line option was found: DEFINE: fooBar = Test
问:
我怎样才能让我的论点是识别的TopShelf,这样我可以消耗他们的价值观?
How can I make my arguments to be recognizable by TopShelf so that I can consume their values?
根据需要指定在这个模式的命令的文档:
According to the documentation you need to specify the commands in this pattern:
-foobar:Test
您还需要添加在您的服务配置的定义:
You also need to add the definition in your service configuration:
string fooBar = null;
HostFactory.Run(configurator =>
{
configurator.AddCommandLineDefinition("fooBar", f=> { fooBar = f; });
configurator.ApplyCommandLine();
// do something with fooBar
configurator.Service<ServiceClass>(settings =>
{
settings.ConstructUsing(s => GetInstance<ServiceClass>());
settings.WhenStarted(s => s.Start());
settings.WhenStopped(s => s.Stop());
});
configurator.RunAsLocalService();
configurator.SetServiceName("ServiceName");
configurator.SetDisplayName("DisplayName");
configurator.SetDescription("Description");
configurator.StartAutomatically();
});
上一篇:最好的方式来绑定Windows窗体属性的applicationSettings在C#中?最好的、窗体、绑定、属性
下一篇:Thread.CurrentPrincipal.Identity VS HttpContext.User.IdentityIdentity、CurrentPrincipal、Thread、User