0

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?

6
  • 1
    By putting your Main() logic inside OnStart() 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. Commented Dec 11, 2014 at 12:47
  • Do you have the code for the Windows Application or is it third-party? Commented Dec 11, 2014 at 12:48
  • @RonDeijkers Actually its kind of a medium sized Application, code is large. Commented Dec 11, 2014 at 12:56
  • Currently I am having a single Solution with a Windows Application & an Empty Windows Service. 2 Different Project in a single Solution Commented Dec 11, 2014 at 12:59
  • Please help me out, I am stucked here... Commented Dec 11, 2014 at 13:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.