How to read System.Threading.Thread.ThreadState by Profiling API (ICofProfilerInfo or any IMetadataImport or any otherway)

StackOverflow https://stackoverflow.com/questions/8278640

Is there a way how to read the System.Thread.ThreadState property of a managed thread by Profiling API ICofProfilerInfo or IMetadataImport interface or any other way from unmanaged code?

For example something like this:

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

解决方案

You can use ICorDebug.GetProcess to get ICorDebugProcess, from which you can get ICorDebugThread by calling GetThread. Then call GetUserState to obtain CorDebugUserState. Beware, though, when using ICorDebug debugger and debugee have to be different processes.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top