Easier way to debug a Windows service

后端 未结 28 1565
春和景丽
春和景丽 2020-11-22 15:36

Is there an easier way to step through the code than to start the service through the Windows Service Control Manager and then attaching the debugger to the thread? It\'s ki

28条回答
  •  囚心锁ツ
    2020-11-22 16:09

    Just paste

    Debugger.Break();
    

    any where in you code.

    For Example ,

    internal static class Program
        {
            /// 
            /// The main entry point for the application.
            /// 
            private static void Main()
            {
                Debugger.Break();
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new Service1()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
    

    It will hit Debugger.Break(); when you run your program.

提交回复
热议问题