【发布时间】:2015-12-20 12:49:21
【问题描述】:
我正在使用 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 行上遇到错误:
Delegate 'Action
签名是
ServiceConfigurator<ServiceClass>.WhenCustomCommandReceived(Action<ServiceClass, HostControl, int> customCommandReceived)
我的 ServiceClass 中已经有了启动、停止、暂停的方法:public void Start() 等。谁能指出我如何设置 Action 的正确方向?谢谢!
【问题讨论】: