调试器分离时是否可以通知应用程序

本文关键字:通知 应用程序 是否 分离 调试器 | 更新日期: 2023-09-27 18:23:51

使用F4分离VS调试器时,也就是停止调试VS调试器是否会引发一些信号或异常,这些信号或异常可以在C++或C#应用程序中捕获?同样的问题是它何时连接,尽管这对我来说用处不大——尽管我想这可以通过在C++中的IsDebuggerPresent上单独旋转线程来解决。

调试器分离时是否可以通知应用程序

Visual studio没有发送任何事件。但你可以这样模拟:

      var t = new Thread(new ThreadStart(() =>
      {
        while (true)
        {
          if (!Debugger.IsAttached)
          {
            //Check if the IsAttached Changed raise a custom event DebuggerDetached
          }
          else
          {
            //Check if the IsAttached Changed raise a custom event DebuggerAttached
          }
          Thread.Sleep(100);
        }
      }));
      t.Start();