D
DC
Hi,
I want to log cpu consumption of individual threads and I also want to
expose the id's of the native threads the managed threads are using
(this number is usefull to check performance in process explorer).
All I am able to retrieve easily is the ManagedThreadId. I could use
what I have found in another forum (see code below) to get the process
info of the current thread. But I have a collection of all
ManagedThreadId's of all plugins my application is using already
available and would like to go from there.
So what I need is something like:
GetNativeThreadIdFromManagedThreadId(Int32 managedThreadId)
TIA for any ideas.
Regards
DC
[DllImport("Kernel32", EntryPoint = "GetCurrentThreadId",
ExactSpelling = true)]
public static extern Int32 GetCurrentWin32ThreadId();
// Call this passing in 0
public static ProcessThread GetProcessThreadFromWin32ThreadId(Int32
threadId)
{
if (threadId == 0) threadId = ThreadUtility.GetCurrentWin32ThreadId
();
foreach (Process process in Process.GetProcesses())
{
foreach (ProcessThread processThread in process.Threads)
{
if (processThread.Id == threadId) return processThread;
}
}
throw new InvalidOperationException("No thread matching specified
thread Id was found.");
}
I want to log cpu consumption of individual threads and I also want to
expose the id's of the native threads the managed threads are using
(this number is usefull to check performance in process explorer).
All I am able to retrieve easily is the ManagedThreadId. I could use
what I have found in another forum (see code below) to get the process
info of the current thread. But I have a collection of all
ManagedThreadId's of all plugins my application is using already
available and would like to go from there.
So what I need is something like:
GetNativeThreadIdFromManagedThreadId(Int32 managedThreadId)
TIA for any ideas.
Regards
DC
[DllImport("Kernel32", EntryPoint = "GetCurrentThreadId",
ExactSpelling = true)]
public static extern Int32 GetCurrentWin32ThreadId();
// Call this passing in 0
public static ProcessThread GetProcessThreadFromWin32ThreadId(Int32
threadId)
{
if (threadId == 0) threadId = ThreadUtility.GetCurrentWin32ThreadId
();
foreach (Process process in Process.GetProcesses())
{
foreach (ProcessThread processThread in process.Threads)
{
if (processThread.Id == threadId) return processThread;
}
}
throw new InvalidOperationException("No thread matching specified
thread Id was found.");
}