我发现这样做的方式是使用Microsoft 的Mdbg工具让我从运行时访问核心调试信息.我正在使用的代码的基本形状如下所示:
MDbgEngine mg;
MDbgProcess mgProcess;
try
{
mg = new MDbgEngine();
mgProcess = mg.Attach(debugProcess.Id);
}
catch (Exception ed)
{
Console.WriteLine("Exception attaching to process " + debugProcess.Id );
throw (ed);
}
mgProcess.CorProcess.EnableLogMessages(true);
mgProcess.CorProcess.OnLogMessage += new LogMessageEventHandler(HandleLogMessage);
mg.Options.StopOnLogMessage = true;
mgProcess.Go().WaitOne();
bool running = true;
Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
while (running)
{
try
{
running =mgProcess.IsAlive;
mgProcess.Go().WaitOne();
}
catch
{
running = false;
}
}
Run Code Online (Sandbox Code Playgroud)
它似乎对我所需要的任何速度都足够好,也许它将为发现自己在同一条船上的任何人提供一个有用的模板.
| 归档时间: |
|
| 查看次数: |
3209 次 |
| 最近记录: |