How do I debug Windows services in Visual Studio?

后端 未结 17 746
梦毁少年i
梦毁少年i 2020-11-28 03:56

Is it possible to debug the Windows services in Visual Studio?

I used code like

System.Diagnostics.Debugger.Break();

but it is givi

17条回答
  •  庸人自扰
    2020-11-28 04:17

    You can make a console application. I use this main function:

        static void Main(string[] args)
        {
            ImportFileService ws = new ImportFileService();
            ws.OnStart(args);
            while (true)
            {
                ConsoleKeyInfo key = System.Console.ReadKey();
                if (key.Key == ConsoleKey.Escape)
                    break;
            }
            ws.OnStop();
        }
    

    My ImportFileService class is exactly the same as in my Windows service's application, except the inheritant (ServiceBase).

提交回复
热议问题