问题标签 [thread-abort]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
165 浏览

android - Titanium:如何在 ANDROID 中按下 BACK 按钮时中止服务呼叫?

0 投票
1 回答
1754 浏览

c# - 停止读取 MSMQ 的服务

我是一名 Java 程序员,被要求对 C# 应用程序进行一些更改。我已经使用 C# 一个星期了,我终于达到了查看文档无济于事的地步,当我用谷歌搜索时也找不到解决方案。

在这种情况下,我有一个 Windows 服务来处理到达 MSMQ 的消息。当收到一条消息时,当前正在侦听的线程会拾取它并开始执行需要几秒钟的操作。

GettingAMessage() 有以下几行监听消息:

问题是,当调用 Stop() 方法并且没有消息进入 MSMQ 时,所有线程都坐在那里等待消息。我尝试过使用超时,但这种方法对我来说似乎并不优雅(并且已经切换到任务工厂,我不确定目前如何实现它们)。我对此的解决方案是将每个线程的引用添加到数组中,以便我可以取消它们。以下是每个工作线程创建后调用的。

然后应该被中止

关于为什么这不会关闭线程的任何建议?(或者更好的是,谁能告诉我应该在哪里寻找如何正确取消 ts.Wait() ?)

0 投票
0 回答
104 浏览

multithreading - 中止被 API 调用阻塞的线程

我有一个 C# WPF 程序,它会阻塞 Windows API 调用。当声卡/Windows 进入错误状态时,调用会永久阻塞线程。

我编写了代码,以便程序执行“超时”并继续执行。但是,Thread.Abort()调用实际上并没有成功中止线程。一旦用户选择按关闭,调用 API 的线程就会继续存在并阻止我的程序稍后关闭。

有没有办法强制关闭挂起的线程?Environment.Exit(1)如果没有,有没有比在这种情况下调用强制关闭应用程序更好的方法来关闭应用程序?

代码的简短版本如下所示:

谢谢!

0 投票
1 回答
5336 浏览

c# - 使用 C# 中的 ID 杀死/中止特定线程

我需要终止一个我已经知道它的 ID 的特定线程,我通过获取它来获取 ID, System.Diagnostics.ProcessThread 并且我已经检测到我需要终止的线程 ID 我可以做些什么来终止它。

0 投票
1 回答
5065 浏览

entity-framework - ADO.Net Entity Framework 线程在读取数据时中止异常

我在使用 ADO.Net Entity 框架读取数据时遇到了一个奇怪的问题。

我有两个表,“调查”和“PatientVists”。“VisitId”是“PatientVists”中的主键,是“surveys”表中的外键。

我正在使用以下查询:

上面的查询似乎很正常。但是在执行查询时,我遇到了线程中止异常。我可以理解是否由于大量数据而导致超时异常。但我不确定为什么会出现线程中止异常。我没有明确地产生一个线程。此代码片段在网络服务中,但我相信它与此无关。

以下是堆栈跟踪:

是重新选择了“ToList”运算符还是“include”运算符产生了一个线程?我应该用加入来代替它吗?一般来说,从性能角度来看,哪种方法是首选方法?

请让我知道是否有人对特定异常有深入了解

谢谢

0 投票
1 回答
275 浏览

c# - 在任务中重新抛出异常不会使任务进入故障状态

考虑以下场景

抛开所有关于中止线程是邪恶的讨论,为什么这段代码不会使任务进入故障状态?但是删除 catch 块或调用

似乎可以解决问题

0 投票
1 回答
879 浏览

c# - Odd behavior: Catching ThreadAbortException and throwing different exception

As a result of investigating this question: Rethrowing exception in Task doesn't make the Task to go to faulted state, I noticed some very odd behavior with the ThreadAbortException that I can't make sense of.

Now, I know that ThreadAbortException is a very special kind of exception to begin with. And the documentation is pretty clear about that when it says:

ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch block.

Scenario #1: Documented behavior.

As expected, the ThreadAbortException is rethrown automatically, resulting in the following output:

Scenario #2: Where it gets interesting is when I decide to throw a different exception in the catch block:

In this case, I assumed that, despite the throwing of the ApplicationException, that the ThreadAbortException would be rethrown anyways to ensure that the documented behavior was preserved. To my surprise, this is the output that resulted:

Did the ApplicationException actually replace and prevent the ThreadAbortException from being thrown?!?

Scenario #3: And finally, to make matters more interesting, I wrap my existing exception handling with one more try-catch layer:

Now I'm not too sure what to expect. Which exception will be caught in the outer catch block? Will it be ApplicationException? And if so, does that mean that I'll be able to swallow the exception and actually manage to print out the will never be reached string after all?

This is the actual output:

From the above output, it looks like the outer catch block does actually catch an ApplicationException. But by the end of that catch block, the ThreadAbortException now all of a sudden reappears out of thin air and gets rethrown?

Question(s): Can someone explain and reconcile scenarios #2 and #3? How is it that in scenario #2, it looks as though the ThreadAbortException is, unexpectedly, replaced by a different exception? Yet, in scenario #3, it looks like ThreadAbortException was still there all along? How is this happening? Is this behavior documented somewhere?

0 投票
1 回答
89 浏览

c# - 在第三方库代码中中止执行的最安全方法

这是我的解决方案中的代码的简化版本,它使用了一个非常有问题的第三方库代码:

对于某些流,构造函数GlitchyThirdPartyComponent完全崩溃并开始消耗大量 CPU 功率和内存,并且在OutOfMemoryException发生之前永远不会退出(在某处闻起来像无限循环)。

我试图找出最安全的调用方式,GetThirdPartyComponent如果它仍在运行,则在某个超时后中止它的执行。

我已经检查了几个可能的解决方案,但似乎没有解决方案适合。有几个原因:

  1. 我无权访问第三方库源代码。所有程序集都被混淆了,所以也没有拆卸
  2. GlitchyThirdPartyComponent不可序列化,因此没有跨应用域或跨进程的解决方案
  3. GlitchyThirdPartyComponent最有可能使用 COM(从它的界面上看),所以Thread.Abort是一个非常不可靠的选择
  4. 虽然可以使用另一个第三方库或向我当前的库供应商寻求错误修复,但这些解决方案需要时间,我的问题应该尽快修复

那么,在这种情况下我应该怎么做呢?这里真的Thread.Abort是最好的解决方案吗?

0 投票
3 回答
1185 浏览

javascript - 中止 XMLHttpRequest 的所有实例

SigWebRefresh我有这行代码以指定的时间间隔(50毫秒)调用该函数。

SigWebRefresh执行XMLHTTPRequest

我曾经使用clearInterval它清除使用 setInterval() 方法设置的计时器。

我想中止所有 XMLHttpRequest 但xhr2.abort();只中止请求的一个实例。如何中止所有未完成的XmlHttpRequest

0 投票
0 回答
46 浏览

c# - 中止 ThreadPool 中所有正在运行的线程并获取线程 ID

我的情况是我正在创建多个线程来执行一项工作。例如,您可以说“工作是处理一些数据”。现在,一旦用户按下“停止”按钮,我想中止所有这些线程并更新数据库中的作业状态。

StartJobThread 是正在执行工作的函数。

请让我知道如何取消当前正在运行的所有线程。以及如何获取正在进行的作业的 ID。这样我就可以更新他们在数据库中的状态。