public static IntPtr? GetExitCodeThread(SafeMemoryHandle threadHandle)
{
// Check if the handle is valid
HandleManipulator.ValidateAsArgument(threadHandle, "threadHandle");
// Create the variable storing the output exit code
IntPtr exitCode;
// Get the exit code of the thread
if (!NativeMethods.GetExitCodeThread(threadHandle, out exitCode))
throw new Win32Exception("Couldn't get the exit code of the thread.");
// If the thread is still active
if (exitCode == new IntPtr(259))
return null;
return exitCode;
}