What's the difference between
Debugger.Launch();
Debugger.Break();
?
What's the difference between
Debugger.Launch();
Debugger.Break();
?
More subtle differences:
If a debugger is already attached, Debugger.Launch is a nop; whereas
Debugger.Break will always break
into the debugger.
Launching a
debugger does not actually break
into the debugger. For example, in
Visual Studio, Debugger.Launch will attach a
debugger to the running process, but
then you still need to do a Debug |
Break in Visual Studio to actually break under
the debugger.
I'm not sure if anyone actually tried what's the difference or if it's different between .NET Framework and .NET 5 but this is the behavior when I test it:
After clicking OK VS will break on Debugger.Launch() (despite other answerers saying it will not):
However the debugger will not break on Debugger.Launch() if it is already attached.
If I pack my project as a dotnet Tool everything is the same except it doesn't know where to break:
TL;DR: In .NET 5:
With debugger attached:
.Launch() will do nothing.Break() will breakWithout debugger attached:
.Launch() will ask to attach a debugger and if you do, it will break at .Launch().Break() will do nothing (no exceptions)Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
Program.cs:
using System;
using System.Diagnostics;
Console.WriteLine("Before break");
Debugger.Break();
Console.WriteLine("After break");
Console.WriteLine("Before Launch");
Debugger.Launch();
Console.WriteLine("After Launch");