Loading...
Loading...
Compare original and translation side by side
Thread.AbortThread.AbortPlatformNotSupportedExceptionThread.AbortThread.AbortPlatformNotSupportedExceptionThread.AbortThreadAbortExceptionThread.ResetAbortThread.InterruptResponse.EndResponse.Redirect(url, true)Thread.AbortPlatformNotSupportedExceptionSYSLIB0006Thread.AbortThreadAbortExceptionThread.ResetAbortThread.InterruptResponse.EndResponse.Redirect(url, true)PlatformNotSupportedExceptionSYSLIB0006Thread.JoinThread.SleepThread.StartThreadAbortExceptionTask.RunParallel.ForEachThread.JoinThread.SleepThread.StartThreadAbortExceptionTask.RunParallel.ForEach| Input | Required | Description |
|---|---|---|
| Source project or solution | Yes | The .NET Framework project containing Thread.Abort usage |
| Target framework | Yes | The modern .NET version to target (e.g., |
| Thread.Abort usage locations | Recommended | Files or classes that reference |
| 输入项 | 是否必填 | 描述 |
|---|---|---|
| 源项目或解决方案 | 是 | 包含Thread.Abort用法的.NET Framework项目 |
| 目标框架 | 是 | 要迁移到的现代.NET版本(如 |
| Thread.Abort用法位置 | 推荐 | 引用 |
Commit strategy: Commit after each pattern replacement so the migration is reviewable and bisectable. Group related call sites (e.g., all cancellable work loops) into one commit.
提交策略:完成每种模式替换后提交一次,使迁移过程可审核、可二分排查。将相关调用点(如所有可取消工作循环)归为一次提交。
Thread.Abortthread.Abort()ThreadAbortExceptionThread.ResetAbortThread.InterruptResponse.End()Response.Redirect(url, true)trueSYSLIB0006Thread.Abortthread.Abort()ThreadAbortExceptionThread.ResetAbortThread.InterruptResponse.End()Response.Redirect(url, true)trueSYSLIB0006| Pattern | Description | Modern replacement |
|---|---|---|
| Cancellable work loop | Thread running a loop that should stop on demand | |
| Timeout enforcement | Aborting a thread that exceeds a time limit | |
| Blocking call interruption | Thread blocked on | |
| ASP.NET request termination | | Return from the action method; use |
| ThreadAbortException as control flow | Catch blocks that inspect | Catch |
| Thread.ResetAbort to continue execution | Catching the abort and calling | Check |
| Uncooperative code termination | Killing a thread running code that cannot be modified to check for cancellation | Move the work to a separate process and use |
| 模式 | 描述 | 现代替代方案 |
|---|---|---|
| 可取消工作循环 | 线程运行需按需停止的循环 | 在循环中检查 |
| 超时强制执行 | 中止超出时间限制的线程 | |
| 阻塞调用中断 | 线程因 | 使用 |
| ASP.NET请求终止 | | 从动作方法返回;使用 |
| ThreadAbortException作为控制流 | 通过捕获 | 改为捕获 |
| Thread.ResetAbort以继续执行 | 捕获中止并调用 | 检查 |
| 非协作式代码终止 | 终止运行无法修改以检查取消请求的代码 | 将工作移至独立进程,使用 |
CancellationTokentoken.ThrowIfCancellationRequested()CancellationTokenSourceCancel()Thread.Abort()new CancellationTokenSource(TimeSpan.FromSeconds(n))cts.CancelAfter(timeout)Task.WhenAny(workTask, Task.Delay(timeout, cts.Token))Thread.Sleep(ms)Task.Delay(ms, token)token.WaitHandle.WaitOne(ms)ManualResetEvent.WaitOne()WaitHandle.WaitAny(new[] { event, token.WaitHandle })Response.End()Response.Redirect(url, true)Response.Redirect(url)trueHttpContext.RequestAbortedcatch (ThreadAbortException)catch (OperationCanceledException)finallyCancellationToken.RegisterOperationCanceledExceptionResetAborttoken.IsCancellationRequestedCancellationTokenSourceCancellationTokenProcess.KillCancellationTokentoken.ThrowIfCancellationRequested()CancellationTokenSourceCancel()Thread.Abort()new CancellationTokenSource(TimeSpan.FromSeconds(n))cts.CancelAfter(timeout)Task.WhenAny(workTask, Task.Delay(timeout, cts.Token))Thread.Sleep(ms)Task.Delay(ms, token)token.WaitHandle.WaitOne(ms)ManualResetEvent.WaitOne()WaitHandle.WaitAny(new[] { event, token.WaitHandle })Response.End()Response.Redirect(url, true)Response.Redirect(url)trueHttpContext.RequestAbortedcatch (ThreadAbortException)catch (OperationCanceledException)finallyCancellationToken.RegisterOperationCanceledExceptionResetAborttoken.IsCancellationRequestedCancellationTokenSourceCancellationTokenProcess.Kill| Removed API | Replacement |
|---|---|
| |
| |
| Check |
| Signal via |
| Remove the call; return from the method |
| |
| Remove after replacing the Thread.Abort call |
| 已移除API | 替代方案 |
|---|---|
| |
| |
| 检查 |
| 通过 |
| 移除调用;从方法返回 |
| 不带endResponse的 |
| 替换Thread.Abort调用后移除 |
SYSLIB0006Thread.AbortThread.AbortThreadAbortExceptionThread.ResetAbortThread.InterruptThread.AbortCancellationTokenSYSLIB0006Thread.AbortThreadAbortExceptionThread.ResetAbortThread.InterruptThread.AbortCancellationTokenThread.AbortThreadAbortExceptionThread.ResetAbortSYSLIB0006CancellationTokenCancellationTokenSource.CancelAfterWaitHandle.WaitAnytoken.WaitHandleThread.AbortThreadAbortExceptionThread.ResetAbortSYSLIB0006CancellationTokenCancellationTokenSource.CancelAfterWaitHandle.WaitAnytoken.WaitHandle| Pitfall | Solution |
|---|---|
Adding | Insert |
| Not passing the token through the full call chain | Every async or long-running method in the chain must accept and forward the |
Expecting | These calls do not check the token. Replace |
Catching | Let |
Not disposing | |
| Assuming cancellation is immediate | Cooperative cancellation only takes effect at the next checkpoint. If work items are large or the code has long gaps between checks, cancellation may be delayed. Design checkpoint frequency based on acceptable latency. |
Using | |
Removing | |
| 陷阱 | 解决方案 |
|---|---|
添加 | 在循环和耗时操作之间的常规检查点插入 |
| 未在完整调用链中传递令牌 | 调用链中的每个异步或长时间运行方法都必须接受并转发 |
期望 | 这些调用不会检查令牌。将 |
捕获并吞掉 | 让 |
未释放 | |
| 认为取消操作是即时的 | 协作式取消仅在下一个检查点生效。若工作项较大或代码中检查点间隔过长,取消可能延迟。根据可接受的延迟设计检查点频率。 |
使用 | |
移除 | |
Thread.AbortPlatformNotSupportedExceptionCancellationTokenThread.AbortThread.InterruptTask.WaitAsync(CancellationToken)Thread.AbortPlatformNotSupportedExceptionCancellationTokenThread.AbortThread.InterruptTask.WaitAsync(CancellationToken)