正确方法
while (!Debugger.IsAttached) {
Thread.Sleep(1000);
}
//下面开始你的代码
以下2中检测调试都无效
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
private static extern bool IsDebuggerPresent();
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);