I am having a Windows Application and I want to run it with WINDOWS SERVICE. I have created a WINDOWS SERVICE Application, now How would I integrate my WIN APP within this windows service application?
1 Answer
This is quite a common requirement and I suggest you to consider the following: My code will be be using the following package : TopShelf
After :
nuget Install-Package Topshelf In your start have something like the following :
public static int Main() { var exitCode = HostFactory.Run ( c => { c.Service<Service> ( sc => { sc.ConstructUsing(name => new Service()); sc.WhenStarted((service, hostControl) => service.Start(hostControl)); sc.WhenStopped((service, hostControl) => Service.Stop(hostControl)); } ); c.SetServiceName("ServiceName"); c.SetDisplayName("DisplayName"); c.SetDescription("Description"); c.EnablePauseAndContinue(); c.EnableShutdown(); c.StartAutomaticallyDelayed(); c.RunAsLocalSystem(); } ); return (int)exitCode; } And follow the configuration available in TopShelf configuration
We are using TopShelf in lots of our projects and it completely fulfills our needs.
Main()logic insideOnStart()and making sure you return from there in time. If you want any more specific help, I'd suggest posting the relevant code and a specific question.