为什么线程会在没有异常抛出的情况下死掉并继续进行? [英] Why does the thread die with no exception thrown and the process continues?

查看:148
本文介绍了为什么线程会在没有异常抛出的情况下死掉并继续进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多线程应用程序:非常激烈的操作。

I have a multi-threaded application: very intense operations.

如此强烈,我称之为与数据库对话的foreach循环。

So intense that I call it a foreach loop that talks to the database.

这是多么复杂。

现在,我已经设置了代码来写出控制台中抛出的任何异常,但更重要的是,我有内置的监视器visual studio告诉我运行代码的IDE中的事件,它将所有异常列为事件。

Now, I have set the code to write out any exception thrown in the Console, but more than that, I have the monitor built into visual studio telling me about events in the IDE running the code which lists all exceptions as events.

因此,我在调试器中看到foreach循环加载项(一般pocos)到一个列表那种类型。

So, I see in the debugger the foreach loop load items (general pocos) into a list of that type.

此时,内存消耗量为200mb +。 CPU使用率在50%到100%之间。

At this point, the amount of memory consumption is 200mb+. The CPU usage yoyos between 50% and 100%.

我有一个带有4个物理内核的i7核心处理器。我正在部署9个线程,同样的事情发生在2个线程上。

I have a i7 core processor with 4 physical cores. I am deploying 9 threads, the same thing happens with 2 threads.

所以foreach循环从不表示它已经死亡,但是,最终代码右下方的foreach永远不会到达,因为如果它曾经它会在调试器中显示我并且它会返回到之前调用它的方法。 

So the foreach loop never signals that it dies, however, eventually the code right bellow the foreach is never reached because if it had been it would have shown me in the debugger and it would have returned to the previous method that called it. 

它正在尝试并捕获:Catch Exception。在使用Visual Studio的事件查看器中永远不会发生异常,并且它不会写入控制台。事实上,Console.WriteLine的断点永远不会被击中。

It is in a try and catch: Catch Exception. The exception never occurs in the event viewer with Visual Studio and it is not written out to the console. In fact the break point at the Console.WriteLine is never hit.

检查所有日志,不会抛出任何异常,没有证据表明它为何死亡并且从未退出for循环。实际上它并没有说线程已中止或退出。什么都不是,它只是死了,继续前进。如果我删除了try并捕获它就会做同样的事情。

Checking around all logs, no exception is thrown, there no evidence why it died and never exited the for loop. In fact it doesn't say Thread Aborted or Exited. Just nothing, it just dies and keeps going. If I remove the try and catch it does the same thing.

为什么没有任何错误或输出表明它死了?

Why is there no error or output of any kind to signal that it died?

推荐答案

也许线程没有死,但是等待一些事件,或者存在死锁(可能是由于共享内容的错误使用造成的),并且循环从不
退出。

为了研究线程,暂停程序并检查Visual Studio中的"线程"窗口。要区分线程,可以为
Thread.Name 指定一个名称。


这篇关于为什么线程会在没有异常抛出的情况下死掉并继续进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆