/// <summary> /// Terminates <see cref="Thread"/> with ID specified. /// </summary> /// <param name="id">ID of the <see cref="Thread"/> to terminate.</param> /// <returns><see langword="true"/> if thread was successfully terminated; /// <see langword="false"/> otherwise.</returns> public static bool TerminateThread(int id) { var handle = NativeCall.OpenThread(0x40000000, false, (uint)id); var result = NativeCall.CancelSynchronousIo(handle); NativeCall.CloseHandle(handle); return(result); }
/// <summary> /// Terminates <see cref="Thread"/> specified. /// </summary> /// <param name="thread"><see cref="Thread"/> to terminate.</param> /// <returns><see langword="true"/> if thread was successfully terminated; /// <see langword="false"/> otherwise.</returns> public static bool TerminateThread(Thread thread) { int code = 0; var id = thread.ManagedThreadId; var handle = NativeCall.OpenThread(0x40000000, false, (uint)id); var result = NativeCall.TerminateThread(handle, code); NativeCall.CloseHandle(handle); return(result != 0); }