Binarysharp.MemoryManagement.Threading.ThreadCore.SuspendThread C# (CSharp) Method

SuspendThread() public static method

Suspends the specified thread.
public static SuspendThread ( SafeMemoryHandle threadHandle ) : uint
threadHandle Binarysharp.MemoryManagement.Native.SafeMemoryHandle A handle to the thread that is to be suspended.
return uint
        public static uint SuspendThread(SafeMemoryHandle threadHandle)
        {
            // Check if the handle is valid
            HandleManipulator.ValidateAsArgument(threadHandle, "threadHandle");

            // Suspend the thread
            var ret = NativeMethods.SuspendThread(threadHandle);

            // If the function failed
            if (ret == uint.MaxValue)
                throw new Win32Exception("Couldn't suspend the thread.");

            return ret;
        }

Usage Example

 /// <summary>
 ///     Either suspends the thread, or if the thread is already suspended, has no effect.
 /// </summary>
 /// <returns>A new instance of the <see cref="FrozenThread" /> class. If this object is disposed, the thread is resumed.</returns>
 public FrozenThread Suspend()
 {
     if (!IsAlive)
     {
         return(null);
     }
     ThreadCore.SuspendThread(Handle);
     return(new FrozenThread(this));
 }