/// <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); }