【问题标题】:How to read System.Threading.Thread.ThreadState by Profiling API (ICofProfilerInfo or any IMetadataImport or any otherway)如何通过 Profiling API(ICofProfilerInfo 或任何 IMetadataImport 或任何其他方式)读取 System.Threading.Thread.ThreadState
【发布时间】:2011-11-26 13:16:08
【问题描述】:

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

例如这样的:

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

【问题讨论】:

    标签: c# .net profiling thread-state imetadataimport


    【解决方案1】:

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

    【讨论】:

    • 这是个好主意和有用的提示,但是我需要在大量使用 ICorProfiler 的过程中获取这些信息。
    • 我想我原来的答案不够清楚 - 我已经编辑过了。从一个进程到另一个进程同时使用 ICorDebug 和 ICorProfiler 非常好。我的观点是该进程不能使用 ICorDebug 来调试自己(与 ICorProfiler 不同,该进程可以是它自己的探查器)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 2018-10-18
    • 2012-07-26
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多