gpt4 book ai didi

wpf - 重新启动应用程序时 System.Windows.Markup.WpfXamlLoader.Load 中的 System.Threading.ThreadAbortException

转载 作者:行者123 更新时间:2023-12-02 00:27:19 24 4
gpt4 key购买 nike

我创建了一个在 Windows 启动时启动的 WPF 应用程序。应用程序检查系统上的文件列表,如果缺少任何文件,它会弹出文件路径。

我面临的问题是当我在应用程序运行时重新启动系统时,重新启动时我的应用程序崩溃并抛出 System.Threading.ThreadAbortException。下面是我在事件日志中得到的堆栈跟踪

Application: FileValidator.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Threading.ThreadAbortException
Stack:
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
at System.Windows.Application.LoadComponent(System.Uri, Boolean)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__1(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
at System.Threading.ExecutionContext.runTryCode(System.Object)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at System.Windows.Application.Run(System.Windows.Window)
at System.Windows.Application.Run()
at FileValidator.App.Main()

这是什么问题,以前有人遇到过这个问题吗???

最佳答案

如果没有更多的调试信息或代码可供查看,就不可能做出明确的回答,但这听起来像是 CLR 的问题。例如,如果您的应用程序在 CLR 运行时完全初始化之前正在执行,您可能会遇到像您在此处遇到的异常。由于 WPF 主要是托管代码,因此我认为这是一种明显的可能性。

我建议您将启动条目从 HKLM 移至 HKCU。这样,它应该在用户登录时加载,而不是在 Windows 启动时加载,这意味着 CLR 将在那时被初始化。

如果这不起作用,MSDN 建议您对 ThreadAbortExceptions 执行 try/catch。我不记得 WPF 是否支持处理,但如果是的话,我会说如果将执行移动到引导堆栈的用户登录部分不能解决问题,那将是你最好的选择。

有用的资源:

http://msdn.microsoft.com/en-us/library/system.threading.threadabortexception.aspx

Is CLR loaded and initialized everytime,when a new managed application is loaded?

关于wpf - 重新启动应用程序时 System.Windows.Markup.WpfXamlLoader.Load 中的 System.Threading.ThreadAbortException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8418492/

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