这个 question has been asked elsewhere on SO ,但没有迹象表明我如何获得 HostControl 的实例,正如帖子所建议的那样。我的 TopShelf 主程序如下所示:

    public static void Main()
    {
        HostFactory.Run(CreateHost);
    }

    private static void CreateHost(HostConfigurator x)
    {
        x.UseLog4Net();

        x.Service<EventBroker>(s =>
        {
            s.ConstructUsing(name => new EventBroker());
            s.WhenStarted(tc => tc.Start());
            s.WhenStopped(tc => tc.Stop());
        });

        x.StartAutomatically();

        x.RunAsNetworkService();
    }

有什么建议么?

最佳答案

更改 WhenStarted 以将 HostControl 像这样传递给它

   s.WhenStarted((tc, hostControl) => tc.Start(hostControl));

每个 TopShelf 文档在这里
http://topshelf.readthedocs.org/en/latest/configuration/config_api.html

关于c# - 如何将 HostControl 实例传递给 TopShelf 中的自定义主机服务?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31062562/

10-11 06:25