public static int HandleToThreadId(SafeMemoryHandle threadHandle)
{
// Check if the handle is valid
ValidateAsArgument(threadHandle, "threadHandle");
// Find the thread id
var ret = NativeMethods.GetThreadId(threadHandle);
// If the thread id is valid
if (ret != 0)
return ret;
//Else the function failed, throws an exception
throw new Win32Exception("Couldn't find the thread id of the specified handle.");
}