C# - How to Create a Windows Service - Part 1/3

By: Fabio Scopel

698   14   197325

Uploaded on 11/21/2012

I go over the basic of creating a windows service.

Guys please join out Google+ Community. It is great place to find help, not only from me, but from many other programmers!

Community is called: Learn C# - The Right way
Google+ Community link: http://bit.ly/Ya9Xwu

See you there!

Thank you for watching! :)

Comments (2):

By anonymous    2017-09-20

Watch 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()

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();

    //In Release this section is used. This is the "normal" way.
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[] 
        new Service1() 

Keep in mind that while this is an awesome way to debug your service. It doesn't call OnStop() unless you explicitly call it similar to the way we called OnStart(null) in the onDebug() function.

Original Thread

Popular Videos 2274694

Submit Your Video

If you have some great dev videos to share, please fill out this form.