以编程方式分离调试器

Sco*_*ain 7 .net c# debugging

我有一个第三方库在内部执行某些操作,导致它在连接调试器时大大减慢,即使在发布模式下也是如此.

我已经找到了100个关于如何在Visual Studio中手动分离调试器的解释Debug -> Detach process.但是,我还没有看到任何人提供一个示例,其中程序可以将任何附加的调试器分离给自己.

基本上是Debugger.Launch()的分离版本?

Pre*_*gha 7

根据你为什么不能在interop-debugging中分离?,CLR不支持分离进程.但Visual Studio可以做到这一点.但这篇文章已有 5年历史了,可以通过pinvoke 使用Windows Api中的DebugActiveProcessStop吗?

BOOL WINAPI DebugActiveProcessStop(
  __in  DWORD dwProcessId
);


[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DebugActiveProcessStop([In] int Pid );
Run Code Online (Sandbox Code Playgroud)

编辑:试过这个:在当前进程中,即使提升,它也会拒绝访问.

CLR Managed Debugger(mdbg)Sample 20062011版本中也有任何内容

最后,本文解释了使用ICorDebug :: Detach需要做什么,我想visual studio确实可以做到这一点.