如何使用WhenCustomCommandReceived设置Topshelf?

时间:2015-12-20 12:49:21

标签: c# topshelf

我正在使用Topshelf创建一个Windows服务(ServiceClass),我正在考虑使用WhenCustomCommandReceived发送自定义命令。

HostFactory.Run(x =>
{
    x.EnablePauseAndContinue();
    x.Service<ServiceClass>(s =>
    {
        s.ConstructUsing(name => new ServiceClass(path));
        s.WhenStarted(tc => tc.Start());
        s.WhenStopped(tc => tc.Stop());
        s.WhenPaused(tc => tc.Pause());
        s.WhenContinued(tc => tc.Resume());
        s.WhenCustomCommandReceived(tc => tc.ExecuteCustomCommand());
    });
    x.RunAsLocalSystem();
    x.SetDescription("Service Name");
    x.SetDisplayName("Service Name");
    x.SetServiceName("ServiceName");
    x.StartAutomatically();
});

但是,我在WhenCustomCommandReceived行上收到错误:

委托'行动&lt; ServiceClass,HostControl,int&gt;'不带1个参数

签名是

ServiceConfigurator<ServiceClass>.WhenCustomCommandReceived(Action<ServiceClass, HostControl, int> customCommandReceived)

我已经有了在ServiceClass中启动,停止,暂停的方法:public void Start()等。有人能指出我如何设置Action的正确方向吗?谢谢!

0 个答案:

没有答案