Is there any way in topshelf to run multiple host in one executable?
// Create hosts
var h1 = HostFactory.New (...); var h2 = HostFactory.New (...)
// Start hosts
in one application Runner.Run (h1, h2);
Solved with threads. But not sure if it is safe...
new Thread (()=>Runner.Run (h1));
new Thread (()=>Runner.Run (h2));
From Topshelf docs:
You can only have ONE service! As of 3.x Topshelf the base product no longer support hosting multiple services. This was done because the code to implement was very brittle and hard to debug. We have opted for a simpler and cleaner base product. This feature will most likely come back in the form of an add on nuget.
Note: This is only valid for pre-3.0 version of Topshelf. In 3.0 this was removed and is being replaced with other methods of hosting multiple services.
There is no way to run multiple hosts. Starting a host blocks execution, does a whole bunch of stuff. You can register multiple logical services in a single host though.
https://github.com/Topshelf/Topshelf/wiki/Creating-a-service
return (int)HostFactory.Run(x => {
x.Service<Service1>({ ... });
x.Service<Service2>({ ... ]);
});
All logical services run under a single AppDomain. This may or may not be an issue. If you need to host them in separate AppDomains, we started working on shelving. http://topshelf-project.com/documentation/shelving/ As a warning, if you're going to start multiple logical services with the same type, make sure they have unique names when configured.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With