【问题标题】:The service did not respond to the start or control request in a timely fashion when using Topshelf使用 Topshelf 时服务没有及时响应启动或控制请求
【发布时间】:2014-05-26 11:39:27
【问题描述】:

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

我的服务配置:

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

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()

【问题讨论】:

    标签: c# service arguments topshelf


    【解决方案1】:

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

    【讨论】:

    • 好吧 - 与注册表混在一起听起来很讨厌!我真的很想用不同的语言启动同一个 exe 的 3 个实例。有什么其他办法吗?我不想拥有 3 个具有不同 app.config 文件的服务副本。如果我可以从同一个主机工厂启动 3 个服务,我会很安全——但从 3.0 版开始就不能这样做了(或者差不多...... .)...
    • 在 GitHub 上发布问题。让我们再讨论一下,也许我们可以想出一个解决方案。但到目前为止,我想不出任何开箱即用的东西。
    • 谢谢 - 遥遥领先 :)
    猜你喜欢
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 2011-03-28
    • 2014-08-05
    • 2011-01-05
    • 1970-01-01
    • 2014-04-08
    相关资源
    最近更新 更多