I am trying to pass a HostControl instance to the start method of a topshelf service but I am getting the following compiler errors:
I have implement the interface 'ServiceControl' for the EventBroker class.
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. Without the 'hostControl' it is working fine.
After some trouble shooting, I found that the 'ServiceControl' wasn't implemented correctly. The Stop/Start methods of the EventBroker didn't have a return type (bool).
Now, with the following Stop/Start Methods it is working.
bool Start(HostControl hostControl)
{
return true;
}
bool Stop(HostControl hostControl)
{
return true;
}