I am trying to create a top-shelf service that depends on input from the command line. But when using the configuration of the command line argument the service can't "start in a timely fashion".
My configuration of the service:
If I remove the configuration of the language setting and hard code the value, the service starts just fine... Any ideas?
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());
});
});
Here's the stacktrace:
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()
So the problem here is that language isn't provided when it starts as a service. You'd need to edit the image-path for the service to include that command line parameter. I think you're much better off reading that from the app.config.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.