如何启动HostFactory.New topshelf服务

时间:2014-08-17 16:05:14

标签: .net topshelf

以下是使用HostFactory方法创建New并声明服务的示例:http://docs.topshelf-project.com/en/latest/configuration/config_api.html#simple-service

HostFactory.New(x =>
{
    x.Service<MyService>();
});

// Service implements the ServiceControl methods directly and has a default constructor
class MyService : ServiceControl
{}

但我无法弄清楚,如何立即启动此服务(如HostFactory.Run(...))?

1 个答案:

答案 0 :(得分:1)

我刚刚找到答案:

public static Host New(Action<HostConfigurator> configureCallback)

返回实现的Host

public interface Host
{
    TopshelfExitCode Run();
}

所以,如果你想开始服务,你必须像这样致电Run

HostFactory.New(x => { x.Service<MyService>(); }).Run();