How to transfer a HostControl instance to a custom host service in TopShelf?

This question was asked elsewhere on SO , but there is no indication of how I get the HostControl instance as the message suggests. My main TopShelf program is as follows:

  public static void Main() { HostFactory.Run(CreateHost); } private static void CreateHost(HostConfigurator x) { x.UseLog4Net(); x.Service<EventBroker>(s => { s.ConstructUsing(name => new EventBroker()); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); x.StartAutomatically(); x.RunAsNetworkService(); } 

Any suggestions?

+3
c # console-application topshelf
source share
1 answer

Change WhenStarted so that HostControl is passed to it as follows

  s.WhenStarted((tc, hostControl) => tc.Start(hostControl)); 

Per TopShelf documentation here http://topshelf.readthedocs.org/en/latest/configuration/config_api.html

+5
source share

All Articles