简体   繁体   English

Topshelf没有达到OnStart方法

[英]Topshelf not hitting OnStart Method

I'm trying to build my first topshelf based service. 我正在尝试构建我的第一个基于topshelf的服务。 I'm trying to follow the pattern in the quick start http://docs.topshelf-project.com/en/latest/configuration/quickstart.html 我正在尝试按照快速入门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());
    }

This code runs straight through and terminates without ever hitting the Onstart method on JobRunner even if I put a break point on the first line. 即使我在第一行上设置了断点,该代码也将直接运行并终止,而无需在JobRunner上点击Onstart方法。

In the hope that someone else can learn from my mistake, the console output actually gives the reason you need to step through carefully or put a Console.Read() at the end to see it 希望其他人可以从我的错误中吸取教训,控制台输出实际上提供了您需要仔细研究或将Console.Read()放在末尾才能看到它的原因。

ConfigurationException: The service was not properly configured: [Failure] Name must not contain whitespace, '/' or '\\' characters ConfigurationException:服务未正确配置:[Failure]名称不得包含空格,'/'或'\\'字符

Windows does support spaces in service names: Windows确实在服务名称中支持空格:

x.SetDisplayName("displayname "); x.SetDisplayName(“ displayname”); //Here is the space //这里是空格

Change it to another value without spaces and must work... 将其更改为另一个没有空格的值,并且必须可以工作...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM