Easier way to debug a Windows service

后端 未结 28 2076
春和景丽
春和景丽 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:06

    When developing and debugging a Windows service I typically run it as a console application by adding a /console startup parameter and checking this. Makes life much easier.

    static void Main(string[] args) {
        if (Console.In != StreamReader.Null) {
            if (args.Length > 0 && args[0] == "/console") {
                // Start your service work.
            }
        }
    }
    

提交回复
热议问题