[英]SynchronizationContext is null in OnStart method of WindowsService
[英]Topshelf not hitting OnStart Method
我正在尝试构建我的第一个基于topshelf的服务。 我正在尝试按照快速入门http://docs.topshelf-project.com/en/latest/configuration/quickstart.html中的模式进行操作
static void Main(string[] args)
{
var h = HostFactory.Run(x =>
{
ConfHost(x);
});
}
private static void ConfHost (Topshelf.HostConfigurators.HostConfigurator x )
{
x.Service<JobRunner>(s =>
{
ConfService(s);
});
x.RunAsLocalSystem();
x.StartAutomatically();
x.SetDescription("topshelf thing");
x.SetDisplayName("displayname ");
x.SetServiceName("svc name");
}
private static void ConfService(ServiceConfigurator<JobRunner> s)
{
s.ConstructUsing(name => new JobRunner());
s.WhenStarted(bt => bt.OnStart());
s.WhenStopped(bt => bt.OnStop());
}
即使我在第一行上设置了断点,该代码也将直接运行并终止,而无需在JobRunner上点击Onstart方法。
希望其他人可以从我的错误中吸取教训,控制台输出实际上提供了您需要仔细研究或将Console.Read()放在末尾才能看到它的原因。
ConfigurationException:服务未正确配置:[Failure]名称不得包含空格,'/'或'\\'字符
Windows确实在服务名称中支持空格:
x.SetDisplayName(“ displayname”); //这里是空格
将其更改为另一个没有空格的值,并且必须可以工作...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.