有没有办法通过分析 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/