以下是使用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(...)
)?
答案 0 :(得分:1)
我刚刚找到答案:
public static Host New(Action<HostConfigurator> configureCallback)
返回实现的Host
:
public interface Host
{
TopshelfExitCode Run();
}
所以,如果你想开始服务,你必须像这样致电Run
:
HostFactory.New(x =>
{
x.Service<MyService>();
}).Run();