Binarysharp.MemoryManagement.Helpers.HandleManipulator.HandleToThread C# (CSharp) Méthode

HandleToThread() public static méthode

Converts an handle into a ProcessThread object assuming this is a thread handle.
public static HandleToThread ( SafeMemoryHandle threadHandle ) : ProcessThread
threadHandle Binarysharp.MemoryManagement.Native.SafeMemoryHandle A valid handle to an opened thread.
Résultat System.Diagnostics.ProcessThread
        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");
        }