C# 线程以代码 0 (0x0) 退出,没有未处理的异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12410548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The thread has exited with code 0 (0x0) with no unhandled exception
提问by Gionata
While debugging my C# application I have noticed a large amount occurrences of the following sentence:
在调试我的 C# 应用程序时,我注意到大量出现以下句子:
The thread -- has exited with code 0 (0x0).
线程 -- 已退出,代码为 0 (0x0)。
The application continues to work and no exception is catched/unhanded.
应用程序继续工作,没有捕获/未处理异常。
The application is running on Windows 7 64bit and debugged with x86 platform.
该应用程序在 Windows 7 64 位上运行并使用 x86 平台进行调试。
采纳答案by BlueM
This is just debugging message. You can switch that off by right clicking into the output window and uncheck Thread Exit Messages.
这只是调试消息。您可以通过右键单击输出窗口并取消选中来关闭它Thread Exit Messages。
http://msdn.microsoft.com/en-us/library/bs4c1wda.aspx
http://msdn.microsoft.com/en-us/library/bs4c1wda.aspx
In addition to program out from your application, the Outputwindow can display the information about:
Modules the debugger has loaded or unloaded.
Exceptions that are thrown.
Processes that exit.
Threads that exit.
除了从您的应用程序中编程外,输出窗口还可以显示以下信息:
调试器已加载或卸载的模块。
抛出的异常。
退出的进程。
退出的线程。
回答by Yahia
if your application uses threads directly or indirectly (i.e. behind the scene like in a 3rd-party library) it is absolutely common to have threads terminate after they are done... which is basically what you describe... the debugger shows this message... you can configure the debugger to not display this message if you don't want it...
如果您的应用程序直接或间接使用线程(即像在 3rd 方库中那样在幕后),线程在完成后终止是绝对常见的...这基本上就是您所描述的...调试器显示此消息...如果您不想要它,您可以将调试器配置为不显示此消息...
If the above does not help then please provide more details since I am not sure what exactly the problem is you face...
如果以上没有帮助,请提供更多详细信息,因为我不确定您面临的问题究竟是什么...
回答by Kek
Well, an application may have a lot of threads running in parallel. Some are run by you, the coder, some are run by framework classes (espacially if you are in a GUI environnement).
好吧,一个应用程序可能有很多并行运行的线程。有些由您(编码员)运行,有些由框架类运行(特别是如果您在 GUI 环境中)。
When a thread has finished its task, it exits and stops to exist. There ie nothing alarming in this and you should not care.
当一个线程完成它的任务时,它退出并停止存在。这没有什么可怕的,你不应该关心。
回答by JoGusto
The framework creates threads to support each window you create, eg, as when you create a Form and .Show() it. When the windows close, the threads are terminated (ie, they exit).
该框架创建线程来支持您创建的每个窗口,例如,当您创建一个 Form 和 .Show() 它时。当窗口关闭时,线程被终止(即,它们退出)。
This is normal behavior. However, if the application is creating threads, and there are a lot of thread exit messages corresponding to these threads (one could tell possibly by the thread's names, by giving them distinct names in the app), then perhaps this is indicative of a problem with the app creating threads when it shouldn't, due to a program logic error.
这是正常行为。但是,如果应用程序正在创建线程,并且有很多与这些线程相对应的线程退出消息(可以通过线程的名称,通过在应用程序中为它们提供不同的名称来判断),那么这可能表明存在问题由于程序逻辑错误,应用程序不应该创建线程。
It would be an interesting followup to have the original poster let us know what s/he discovered regarding the problems with the server crashing. I have a feeling it wouldn't have anything to do with this... but it's hard to tell from the information posted.
让原始海报让我们知道他/她发现了有关服务器崩溃问题的内容,这将是一个有趣的后续行动。我有一种感觉,这与此无关……但从发布的信息中很难判断。
回答by alphanoch
In order to complete BlueM's accepted answer, you can desactivate it here:
为了完成 BlueM 接受的答案,您可以在此处停用它:
Tools > Options > Debugging > General Output Settings > Thread Exit Messages : Off
工具 > 选项 > 调试 > 常规输出设置 > 线程退出消息:关闭
回答by tonyb
Executing Linq queries can generate extra threads. When I try to execute code that uses Linq query collection in the immediate window it often refuses to run because not enough threads are available to the debugger.
执行 Linq 查询会生成额外的线程。当我尝试在即时窗口中执行使用 Linq 查询集合的代码时,它经常拒绝运行,因为没有足够的线程可供调试器使用。
As others have said, for threads to exit when they are finished is perfectly normal.
正如其他人所说,线程在完成时退出是完全正常的。
回答by shanansari
I have also faced this problem and the solution is:
我也遇到过这个问题,解决方法是:
- open Solution Explore
- double click on Program.cs file
- 打开解决方案探索
- 双击 Program.cs 文件
I added this code again and my program ran accurately:
我再次添加了这段代码,我的程序运行准确:
Application.Run(new PayrollSystem());
//File name this code removed by me accidentally.

