Debugging Windows Services

I created a Windows service and installed it manually. Later I started the service from the "Service" tool. Now I want to run a dubug application for Windows from the Visual Studio IDE. When I try to connect this process on the Debug tab in the IDE, the list shows the Windows maintenance process, but it does not highlight for attachment. Is there any other main process that I have to attach to debug a service application. Any relevant informed information is appreciated.

Thank.

+3
source share
5 answers

, , , Windows, , ( ) ( ). "" "", .

, Main :

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    private static void Main(string[] args)
    {
        if (args.Length > 0 && args[0] == "/form")
        {
            var form = new MainForm();
            Application.Run(form);
            return;
        }

        var servicesToRun = new ServiceBase[]
        {
            new BackgroundService()
        };

        ServiceBase.Run(servicesToRun);
    }
}

" " Visual Studio "/form", . , - . "", , .

+5

, , - System.Diagnostics.Debugger.Break() Main(), OnStart() . SCM, , Visual Studio . . .

, , Windows. , "attach to", , , . , , . , , .

EDIT:

, @divo, Windows ( ).

  • "" | " " | "" | " ".
  • " ".
  • " ". .

, , .

+4

:

-

, - System.Diagnostics.Trace. , , Sysinternal DbgView.

+1

Well, this is a rather old question, but no one said that, so I decided that I would at least mention that I just met. Make sure that in the Attach to Process dialog box, you select Show processes from all users. Until I did this, I could only see my .vshost.exe file in the process list.

+1
source

If you have JIT debugging enabled, DebugBreak () at startup will allow you to run it in the debugger.

0
source

Source: https://habr.com/ru/post/1726934/


All Articles