关于进程'n'线程的问题#2 [英] Question on processes 'n' threads #2

查看:159
本文介绍了关于进程'n'线程的问题#2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一项服务可以启动需要很长时间的额外线程,这样它可以在长进程运行时响应事件。我只是想知道,


a)如果在一个工作线程中抛出一个异常并且它未被处理,它是否会导致整个应用程序关闭或只是遭受它的工作线程?


b)如果在没有异常处理但调用它的函数的函数中抛出异常,异常会直到它找到一个处理程序,然后再考虑该处理程序是该例外的官方处理程序?


谢谢

Hi

I have a service which starts extra threads which take a long time, this is so it can respond to events while long processes are running. I was just wondering,

a) if an exception is thrown in a worker thread and it is unhandled, does it bring the whole application down or just the worker thread that suffered it?

b) if an exception is thrown in a function which doesn''t have exception handling but the function that called it does, will the exception simply propogate up until it finds a handler, and then consider that handler to be the official handler of that exception?

Thanks

推荐答案

Beeeeeeeeeeeeves,

见内联:


" Beeeeeeeeeeeeves" <成为************** @ discussions.microsoft.com>写在

消息新闻:2B ********************************** @ microsof t.com ...
Beeeeeeeeeeeeves,

See inline:

"Beeeeeeeeeeeeves" <Be**************@discussions.microsoft.com> wrote in
message news:2B**********************************@microsof t.com...


我有一个服务,它会启动需要很长时间的额外线程,这个
是这样它可以响应事件而长进程正在运行。我只是想知道,
a)如果在一个工作线程中抛出一个异常并且它未被处理,那么它会使整个应用程序关闭或只是工作线程遭受了吗?
呢?


我相信应用程序会关闭,因为例外是

未处理
< br)如果在没有异常
处理的函数中抛出异常但是调用它的函数会抛出异常,那么异常只会在它找到之前传播,直到它找到一个处理程序,然后认为该处理程序是

该异常的官方处理程序?


如果函数中没有异常处理程序那个异常

被抛出,然后异常会冒出调用堆栈,直到它处理完b
,或者,应用程序终止。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

谢谢
Hi

I have a service which starts extra threads which take a long time, this is so it can respond to events while long processes are running. I was just
wondering,
a) if an exception is thrown in a worker thread and it is unhandled, does it bring the whole application down or just the worker thread that suffered
it?

I believe that the application will shut down, as the exception is
unhandled

b) if an exception is thrown in a function which doesn''t have exception handling but the function that called it does, will the exception simply
propogate up until it finds a handler, and then consider that handler to be
the official handler of that exception?

If there is not an exception handler in the function that the exception
was thrown in, then the exception will bubble up the call stack until it is
handled, or, the application terminates.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Thanks



我有一个启动额外线程的服务需要很长时间,因此它可以在长进程运行时响应事件。我是
I have a service which starts extra threads which take a long time, this is so it can respond to events while long processes are running. I was



只是想知道,


just wondering,


a)如果在工作线程中抛出异常并且它未被处理,

a) if an exception is thrown in a worker thread and it is unhandled,


是否会导致整个应用程序关闭或只是
遭受的工作线程?

我相信应用程序将关闭,因为例外是未处理的

does it bring the whole application down or just the worker thread that suffered it?

I believe that the application will shut down, as the exception is
unhandled




我相信只有发生异常的线程才会被杀,

其他人将继续运行,。


我刚刚在MSDN的一篇文章中找到了这个:


这是

正在执行的未处理的异常处理程序默认行为的摘要在这个应用程序中。

a ..应用程序主线程上发生的未处理异常导致

申请终止。

b ..除了

应用程序的主线程之外的线程中发生的未处理的异常被CLR吞噬。这包括手动的

线程,线程池线程和CLR的终结器线程。如果您的

应用程序是一个控制台应用程序,CLR会将异常文本输出到

控制台(尽管您的应用程序仍在运行)。如果您的应用程序不是
a控制台应用程序,当发生异常

并且您的应用程序继续运行时,没有向外指示。

c ..通过Windows窗体类抽取窗口的线程上发生的未处理异常受Windows窗体

未处理异常处理程序的约束。默认情况下会生成一个调试对话框,但

可以覆盖此行为(稍后会详细介绍)。


干杯,


-

Ignacio Machin,

ignacio.machin at dot.state.fl.us

Florida Department交通运输



I believe that only the thread where the exception happen is kill, the
others will continue to run, .

I just found this on an article in MSDN:

Here is a summary of the unhandled exception handler default behaviors that
are executing in this application.
a.. Unhandled exceptions that occur on the application''s main thread cause
the application to terminate.
b.. Unhandled exceptions that occur in threads other than the
application''s main thread are swallowed by the CLR. This includes manual
threads, thread pool threads, and the CLR''s finalizer thread. If your
application is a console application, the CLR outputs exception text to the
console (though your application keeps running). If your application is not
a console application, there is no outward indication when an exception
occurs and your application keeps running.
c.. Unhandled exceptions that occur on a thread that is pumping window
messages via the Windows Forms classes are subject to the Windows Forms
unhandled exception handler. A debug dialog box is produced by default, but
this behavior can be overridden (more on this in a moment).

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation




" Beeeeeeeeeeeeves" <成为************** @ discussions.microsoft.com>写在

消息新闻:02 ********************************** @ microsof t.com ...

"Beeeeeeeeeeeeves" <Be**************@discussions.microsoft.com> wrote in
message news:02**********************************@microsof t.com...
所以,最好不要依赖它,那么..?
so, "best not to rely on it", then..?




那么我怎么能处理我想在我的一个子线程抛出异常时向用户显示错误消息的情况?


问候

Kiran



So how can I handle a situation in which I want to show a error message to
the user when one of my child thread throws a exception?

regards
Kiran


这篇关于关于进程'n'线程的问题#2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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