[英]Topshelf C# Windows Service - Cannot pass HostControl
I am trying to pass a HostControl instance to the start method of a topshelf service but I am getting the following compiler errors: 我试图将HostControl实例传递给topshelf服务的start方法,但遇到以下编译器错误:
I have implement the interface 'ServiceControl' for the EventBroker class. 我已经为EventBroker类实现了接口“ ServiceControl”。
using Topshelf;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
HostFactory.Run(x =>
{
x.Service<EventBroker>(s =>
{
s.ConstructUsing(name => new EventBroker());
s.WhenStarted((tc, hostControl) => tc.Start(hostControl));
s.WhenStopped(tc => tc.Stop());
});
x.RunAsLocalSystem();
Am I missing some an assembly reference or something else? 我是否缺少一些装配参考或其他参考? I am using TopShelf v3.3.154.0.
我正在使用TopShelf v3.3.154.0。 Without the 'hostControl' it is working fine.
没有“ hostControl”,它可以正常工作。
After some trouble shooting, I found that the 'ServiceControl' wasn't implemented correctly. 经过一些故障排除后,我发现“ ServiceControl”未正确实现。 The Stop/Start methods of the EventBroker didn't have a return type (bool).
EventBroker的Stop / Start方法没有返回类型(布尔型)。
Now, with the following Stop/Start Methods it is working. 现在,通过以下“停止/启动方法”,它可以正常工作。
bool Start(HostControl hostControl)
{
return true;
}
bool Stop(HostControl hostControl)
{
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.