How to debug a Windows Service written in C# flawlessly

How to debug a Windows Service written in C# flawlessly - welcome to our blog that presents the full content How Gadget, the discussion this time we're discussing that you find that How to debug a Windows Service written in C# flawlessly, we have provided complete information with images that are easy to understand, the explanation is simple but complete, therefore please read until the end :)

This is about : How to debug a Windows Service written in C# flawlessly
And this article : How to debug a Windows Service written in C# flawlessly

You can also see our article on:


    How to debug a Windows Service written in C# flawlessly

    Hi guys,

    I know its been frustrating to install and uninstall and stop and start ,each and every time you have modified your windows service.



    If you tried to directly Run or Press F5 ,then this will be the result from Visual Studio.

    How to debug a C# written windows service

    • After creating a C# -> Windows Service project.
    • Double click "Program.cs" from the 'Solution explorer' from in VS.
    • Now change the code in function main() to the code mentioned below.
    static void Main()
    {
    #if(!DEBUG)
    ServiceBase[] ServicesToRun;
    ServicesToRun = new ServiceBase[]
    new Service1() //Replace this with your service class name
    ServiceBase.Run(ServicesToRun);
    #else
    Service1 myServ = new Service1(); //Replace this with your service class name
    myServ.main();//This will invoke the function which contains the code you should put in OnStart when the real service runs.Just define a function called main and copy the code that you had put in OnStart. 

    #endif
    }

    Explanation of the above code

    If the Runtime configuration is set to "Debug" then the service will run as an ordinary Console application.You may set break points and debug.


    If the Runtime configuration is set to anything else ,other than "Debug" then it will run as a normal service which responds to installutil and net start or stop commands.


    Hope this helped you a lot in your programming career.Any comments, feel free to use the comment box below


    Information How to debug a Windows Service written in C# flawlessly has been completed we present

    A few of our information about the How to debug a Windows Service written in C# flawlessly, we hope you benefit from this article

    You have just read the article How to debug a Windows Service written in C# flawlessly and many articles about gadget in our blog this, please read it. and url link of this article is https://howtomonetizeeverything.blogspot.com/2015/12/how-to-debug-windows-service-written-in.html Hopefully discussion articles on provide more knowledge about the world of tech gadgets.

    Tag :

    Related Posts :

    • iCall iNote3ROM install:- Unpack FlashTools in the ROM , and Click on Flash_tool.exe- Select a the MT6735M_Android_scatter.txt in ROM- Wait file to be a… Read More...
    • iCall iNote1ROM install:- Unpack FlashTools in the ROM , and Click on Flash_tool.exe- Select a the MT6735M_Android_scatter.txt in ROM- Wait file to be a… Read More...
    • iCall iNote6                                      &n… Read More...
    • iCall iNote5 ROM install:- Unpack FlashTools in the ROM , and Click on Flash_tool.exe- Select a the MT6735M_Android_scatter.txt in ROM- Wait file to be a… Read More...
    • iCall iNote2ROM install:- Unpack FlashTools in the ROM , and Click on Flash_tool.exe- Select a the MT6735M_Android_scatter.txt in ROM- Wait file to be a… Read More...

    0 Response to "How to debug a Windows Service written in C# flawlessly"

    Post a Comment