2

Currently, when calling Debugger.Launch(); from a running application, VisualStudio breaks execution at the line where the debugger is launched and then I have to manually continue code execution.

Is there a way to stop it from doing that and to just attach the debugger without breaking at the line where it's launched?

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
IneedHelp
  • 1,630
  • 1
  • 27
  • 58

1 Answers1

-1

If you run your app in Visual Studio using F5 (Debug|Start Debugging) then the debugger will start attached, no need for Debugger.Launch().

If your app is running externally then you can attach the VS debugger whenever you want to by using Debug|Attach to Process... and (based on a very quick test I've just done) this does not break into the process.

If you want to programatically attach the debugger from within a running process then this question and it's answers might help Attach debugger in C# to another process. Note in particular Dave Hillier's self-answer where he mentions it might be possible to use Process.Start to run vsjitdebugger.exe -p ProcessId.

Rhys Jones
  • 5,348
  • 1
  • 23
  • 44
  • I did specify that I am launching it from a running application and that's how I need to do it because it's dynamic, I am not always launching the debugger, nor do I want to have it attached at startup all the time. – IneedHelp Sep 16 '20 at 09:20
  • I'm already doing that, I have a button I press on the application's UI and it runs `Debugger.Launch();`, then a dialog box shows up asking me which debugger I want to use and I select the running VisualStudio instance, all good so far, but then VisualStudio breaks on the line where the debugger has been launched, and I don;t want it to do that, cause I have to manually instruct it to continue running after that. – IneedHelp Sep 16 '20 at 11:27
  • @IneedHelp so how about my 2nd point - use Debug|Attach to Process... ? Can you describe a bit more about what you're trying to achieve? – Rhys Jones Sep 16 '20 at 11:35
  • imagine I am starting an application and on its UI it has a button; when I click that button, it runs the debugger launch method which initiates the VisualStudio debugger (that I already have opened). The problem I have with it is that VisualStudio breaks execution at the line where the debugger is launched and then I have to manually continue code execution (F5). What I want is that VisualStudio doesn't break code execution when I launch the debugger, but it might not be possible.. I'm not sure tho, that's why I am asking. – IneedHelp Sep 16 '20 at 17:49
  • @IneedHelp, maybe you should extend Debugger to create your own debugger. – Mr Qian Sep 22 '20 at 09:59