3

I am writing a windows service. This service runs another process I've developed through Process class methods, but I want to run this process on debug mode also, using breakpoints, for instance.

How can I do this?

Victor Rodrigues
  • 11,353
  • 23
  • 75
  • 107

3 Answers3

4

When debugging a service, DebugBreak() is very nice. You can even debug the startup of the service, which can be very hard to time if you try to attach the process.

In C#

#if DEBUG
  System.Diagnostics.Debugger.Break();
#endif

In C++

#if DEBUG
  System.Diagnostics.Debugger.Break();
#endif

Also see the question: how can I use debugbreak() in C#.

Community
  • 1
  • 1
Ulf Lindback
  • 13,974
  • 3
  • 40
  • 31
2

From the main menu "Debug->Attach Process".

Ali Ersöz
  • 15,860
  • 11
  • 50
  • 64
1

As well as the "attach process" mode, I've sometimes found it's handy to have an executable that you can run directly from Visual Studio (or just as a console app). I can't remember whether there were any difficulties in doing so, but I don't think there were... you just need to provide a normal entry point as well as the service entry point.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194