2

我正在尝试创建一个依赖于命令行输入的顶级服务。但是当使用命令行参数的配置时,服务不能“及时启动”。

我的服务配置:

如果我删除语言设置的配置并对值进行硬编码,服务启动就好了......有什么想法吗?

HostFactory.Run(conf =>
{
CultureInfo language = null; 

conf.AddCommandLineDefinition("language", lang => { language = new CultureInfo(lang); });
conf.ApplyCommandLine();
var countryCode = new RegionInfo(language.Name).TwoLetterISORegionName.ToUpper();
conf.SetDescription("{0} Order Broker".FormatWith(countryCode));
conf.SetDisplayName("{0} Order Broker".FormatWith(countryCode));
conf.SetServiceName("{0}OrderBroker".FormatWith(countryCode));

conf.StartAutomatically();
conf.RunAsLocalSystem();
conf.Service<IOrderService>(svc =>
{
   svc.ConstructUsing(name => Creator.Current.Create<IOrderService>());
   svc.WhenStarted(service => service.Start(language));
   svc.WhenStopped(service => service.Stop());
});
});

这是堆栈跟踪:

System.ComponentModel.Win32Exception: The service did not respond to the start
or control request in a timely fashion --- End of inner exception stack trace ---
at System.ServiceProcess.ServiceController.Start(String[] args)
at System.ServiceProcess.ServiceController.Start()
at Topshelf.Runtime.Windows.WindowsHostEnvironment.StartService(String serviceName)
at Topshelf.Hosts.StartHost.Run()
4

1 回答 1

0

所以这里的问题是当它作为服务启动时没有提供语言。您需要编辑服务的图像路径以包含该命令行参数。我认为您最好从 app.config 中阅读它。

于 2014-04-12T23:13:09.887 回答