Easier way to debug a Windows service

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

    I use a variation on JOP's answer. Using command line parameters you can set the debugging mode in the IDE with project properties or through the Windows service manager.

    protected override void OnStart(string[] args)
    {
      if (args.Contains("DEBUG_SERVICE"))
      {
        Debugger.Break();
      }
      ...
    }
    

提交回复
热议问题