/// <summary> /// [无异常]终止线程 /// </summary> /// <param name="t"></param> public static void Abort(System.Threading.Thread t) { if (t != null) { if (t.ThreadState == System.Threading.ThreadState.Background || t.ThreadState == System.Threading.ThreadState.Running || t.ThreadState == System.Threading.ThreadState.Suspended || t.ThreadState == System.Threading.ThreadState.WaitSleepJoin ) { t.Abort(); } } }
public static void Abort(ref System.Threading.Thread thread, System.TimeSpan timeout, System.Threading.ThreadState state = System.Threading.ThreadState.Stopped) { //If the worker IsAlive and has the requested state. if (thread != null && (thread.IsAlive && thread.ThreadState.HasFlag(state))) { //Attempt to join if (false == thread.Join(timeout)) { try { //Abort thread.Abort(); } catch (System.Threading.ThreadAbortException) { System.Threading.Thread.ResetAbort(); } catch { throw; } //Cancellation not supported } //Reset the state of the thread to indicate success thread = null; } }
public override void CancelDownload(System.Threading.Thread downloadThread) { cancel = true; if (downloadThread != null) { downloadThread.Abort(); downloadThread.Join(3000); } }
private void AbortRequestContext(System.ServiceModel.Channels.RequestContext requestContext) { try { requestContext.Abort(); ReceiveContextRPCFacet receiveContext = this.ReceiveContext; if (receiveContext != null) { this.ReceiveContext = null; CallbackState state = new CallbackState { ReceiveContext = receiveContext, ChannelHandler = this.channelHandler }; IAsyncResult result = receiveContext.BeginAbandon(TimeSpan.MaxValue, handleEndAbandon, state); if (result.CompletedSynchronously) { receiveContext.EndAbandon(result); } } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.channelHandler.HandleError(exception); } }