Binarysharp.MemoryManagement.Threading.ThreadCore.GetExitCodeThread C# (CSharp) Méthode

GetExitCodeThread() public static méthode

Retrieves the termination status of the specified thread.
public static GetExitCodeThread ( SafeMemoryHandle threadHandle ) : IntPtr?
threadHandle Binarysharp.MemoryManagement.Native.SafeMemoryHandle A handle to the thread.
Résultat IntPtr?
        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;
        }

Usage Example

        /// <summary>
        ///     Gets the termination status of the thread.
        /// </summary>
        public T GetExitCode <T>()
        {
            // Get the exit code of the thread (can be nullable)
            var ret = ThreadCore.GetExitCodeThread(Handle);

            // Return the exit code or the default value of T if there's no exit code
            return(ret.HasValue ? MarshalType <T> .PtrToObject(MemorySharp, ret.Value) : default(T));
        }