gpt4 book ai didi

c# - WPF AppDomain UnhandledException 处理程序超时

转载 作者:行者123 更新时间:2023-11-30 18:31:55 27 4
gpt4 key购买 nike

AppDomain 有未处理的异常时,您可以处理 AppDomain.CurrentDomain.UnhandledException 事件。

但是,您无法阻止 AppDomain 关闭。你不能只是阻塞线程。最终 AppDomain 将关闭它。

在 ASP.NET 中,如果您注册了对象 (IRegisteredObject),AppDomain 将为您的代码提供 30 秒的运行时间。

有谁知道标准 WPF 应用程序的超时时间是多少?

最佳答案

我不知道如何为 DispatcherUnhandledException 处理程序设置超时

但是,应用程序是否以 Environment.ExitApplication.Exit 终止,其中存在未处理的异常?

引用:http://www.dev102.com/2008/06/24/how-do-you-exit-your-net-application/

Environment.Exit - From MSDN: Terminates this process and gives theunderlying operating system the specified exit code. This is the codeto call when you are using console application.

Application.Exit -From MSDN: Informs all message pumps that they must terminate, andthen closes all application windows after the messages have beenprocessed. This is the code to use if you are have calledApplication.Run (WinForms applications), this method stops all runningmessage loops on all threads and closes all windows of theapplication. There are some more issues about this method, read aboutit in the MSDN page.

对于 WPF,如果未处理的异常会导致应用程序崩溃并出现 Environment.Exit(与 Application.Exit 一样)- 我怀疑应用程序在所有线程完成之前不会退出。如果是这样,那么您可以尝试通过 DispatcherUnhandledException 处理程序中的线程执行您需要执行的操作。

你能告诉我这是否也是这种行为吗?我好奇。我们从来没有遇到过这个问题,因为在 WPF DispatcherUnhandledException 处理程序上我们只对磁盘进行简单的日志记录

关于c# - WPF AppDomain UnhandledException 处理程序超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19326825/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com