C# - How to Create a Windows Service - Part 1/3
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about installing, starting and debugging a C# Windows service, especially the trick of calling OnStart from Main under a DEBUG build.
Recommended by 4 people across 3 different months, 2013 to 2016.
What it is
A short 2012 screencast showing how to create a Windows service in C# with Visual Studio, covering the basic service template, the installer, and a technique for debugging the service. It is part 1 of a 3-part series from the Coffee Cup Dev channel.
What people said
Strong rec zszep · 2013-09 · Stack Overflow · on “window service installation issues”
You need to add a service installer by clicking add installer on the service designer pane. There is a great video on creating and installing windows services using C# on [this video] .
Recommends Cesar · 2013-06 · Stack Overflow · on “Windows service start failure: Cannot start service from the command line or debugger”
Watch this video [this video] , I had the same question. He shows you how to debug the service as well. Here are his instructions using the basic C# Windows Service template in Visual Studio 2010/2012. You add this to the Service1.cs file: public void onDebug() { OnStart(null); } You change your Main() to call your service this way if you are in the DEBUG Active Solution Configuration. static void Main() { #if DEBUG //While debugging this section is used. Service1 myService = new Service1(); myService.onDebug(); System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); #else //In Release this section is used. This is the "normal" way. ServiceBase[] ServicesToRun; ServicesToRun = new Servi
Recommends Jason Miller · 2013-09 · Stack Overflow · on “Easier way to debug a Windows service”
This [this video] explains how to debug a Windows service quite nicely... the actual method of doing it starts at 4:45 in the video... Here is the code explained in the video... in your Program.cs file, add the stuff for the Debug section... namespace YourNamespace { static class Program { /// <summary> /// The main entry point for the application. /// </summary> static void Main() { #if DEBUG Service1 myService = new Service1(); myService.OnDebug(); System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); #else ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); #endif } } } In your Service1.cs file, add the OnDebug() method
Recommends Ahmer Ali Ahsan · 2016-05 · Stack Overflow · on “Windows Service started and then stopped, but no logging”
take a look at [this video] and flow these steps how to create a windows service in c#. I got this same error after watching these steps My error was gone.