c# - 如何通过分析 API(ICofProfilerInfo 或任何 IMetadataImport 或任何其他方式)读取 System.Threading.Thread.ThreadState

标签 c# .net profiling thread-state imetadataimport

有没有办法通过分析 API ICofProfilerInfo 或 IMetadataImport 接口(interface)或任何其他方式从非托管代码读取托管线程的 System.Thread.ThreadState 属性?

例如这样的事情:

ICorProfilerInfo3 pProfilerInfo = ...;
ThreadID threadId;
pProfilerInfo->GetCurrentThreadID(&threadId);
ThreadState threadState;
pSomethingWhatINeed->GetManagedTheadState(threadId, &threadState);
if(threadState == THREADSTATE_WAIT_JOIN_SLEEP){
  //do something
}

最佳答案

可以使用ICorDebug.GetProcess获取ICorDebugProcess,从中可以通过调用GetThread获取ICorDebugThread 。然后调用GetUserState获取CorDebugUserState 。但请注意,使用 ICorDebug 时调试器和被调试者必须是不同的进程。

关于c# - 如何通过分析 API(ICofProfilerInfo 或任何 IMetadataImport 或任何其他方式)读取 System.Threading.Thread.ThreadState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8278640/

相关文章:

.net - 为什么 SynchronizedCollection<T> 在 System.ServiceModel 程序集中?

c# - 日期时间支持的格式化语言?

c++ - 使用 STL vector 优化算术运算

java - Thread.run 在探查器日志中占用大量 CPU 时间

perl - 是否可以只对 Perl 中的子例程调用进行计时?

c# - 使用 wp8 内置 json 类反序列化带有空格的 Json 属性名称

c# - razor View 引擎中的全局函数

c# - 如何使用 WPF 按钮或超链接打开资源管理器窗口以浏览给定的 UNC 路径?

c# - 如果在 C# 中的 Using 语句中调用连接关闭事件会发生什么

c# - MS UIAutomation 对文本没用吗?如何设置字体粗细、获取插入位置、插入文本等?