public static ProcessThread HandleToThread(SafeMemoryHandle threadHandle)
{
// Search the thread by iterating the processes list
foreach (var process in Process.GetProcesses())
{
var ret = process.Threads.Cast<ProcessThread>().FirstOrDefault(t => t.Id == HandleToThreadId(threadHandle));
if (ret != null)
return ret;
}
// If no thread was found, throws a exception like the First() function with no element
throw new InvalidOperationException("Sequence contains no matching element");
}