wpf System. InvalidOperationException:'Dispatcher处理已挂起,但仍在处理邮件,'

jjjwad0x  于 2023-06-24  发布在  其他
关注(0)|答案(3)|浏览(88)

我创建了一个空白的WPF应用程序

<Window x:Class="WpfApp4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp4"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <WebBrowser Name="WebBrowser1" ></WebBrowser>
    </Grid>
</Window>

单击“运行”时,将显示此异常
System. InvalidOperationException:'Dispatcher处理已挂起,但仍在处理邮件。'
如果我删除WebBrowser,那么应用程序运行时不会出现异常。它给出了这个异常,然后几分钟前,我可以运行类似的代码,而不是它给出了这个意外异常,然后现在它坚持使用这个异常。如何解决?
我认为这个问题是在Visual Studio更新到版本15.4.0之后开始的。
我的Windows:Microsoft Windows [版本10.0.15063]
堆栈跟踪:

System.InvalidOperationException occurred
  HResult=0x80131509
  Message=Dispatcher processing has been suspended, but messages are still being processed.
  Source=<Cannot evaluate the exception source>
  StackTrace:
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.IOleObject.SetClientSite(IOleClientSite pClientSite)
   at System.Windows.Interop.ActiveXHost.TransitionFromLoadedToRunning()
   at System.Windows.Interop.ActiveXHost.TransitionUpTo(ActiveXState state)
   at System.Windows.Interop.ActiveXHost.BuildWindowCore(HandleRef hwndParent)
   at System.Windows.Interop.HwndHost.BuildWindow(HandleRef hwndParent)
   at System.Windows.Interop.HwndHost.BuildOrReparentWindow()
   at System.Windows.Interop.HwndHost.OnSourceChanged(Object sender, SourceChangedEventArgs e)
   at System.Windows.SourceChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.PresentationSource.UpdateSourceOfElement(DependencyObject doTarget, DependencyObject doAncestor, DependencyObject doOldParent)
   at System.Windows.PresentationSource.OnVisualAncestorChanged(DependencyObject uie, AncestorChangedEventArgs e)
   at System.Windows.UIElement.OnVisualAncestorChanged(Object sender, AncestorChangedEventArgs e)
   at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
   at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
   at System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
   at System.Windows.Media.Visual.AddVisualChild(Visual child)
   at System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
   at System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(FrameworkElement container)
   at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   at System.Windows.FrameworkElement.ApplyTemplate()
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Border.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Window.MeasureOverrideHelper(Size constraint)
   at System.Windows.Window.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
   at System.Windows.Window.SetRootVisual()
   at System.Windows.Window.SetRootVisualAndUpdateSTC()
   at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
   at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
   at System.Windows.Window.CreateSourceWindowDuringShow()
   at System.Windows.Window.SafeCreateWindowDuringShow()
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at WpfApp4.App.Main()

我的Visual Studio 2017信息:
Microsoft Visual Studio Community 2017版本15.4.0 VisualStudio.15.Release/15.4.0 + 27004.2002 Microsoft. NET Framework版本4.7.02046
安装版本:社区
Visual Basic 2017 00369 - 60000 - 00001-AA133 Microsoft Visual Basic 2017
Visual C#2017 00369 - 60000 - 00001-AA133 Microsoft Visual C#2017
目视检查F#4.1 00369 - 60000 - 00001-AA133 Microsoft目视检查F#4.1
Visual Studio应用程序洞察工具包8.9.00809.2 Visual Studio应用程序洞察工具
ASP.NET and Web Tools 2017 15.0.30925.0 ASP.NET and Web Tools 2017
ASP.NET Core Razor语言服务1.0为ASP.NET Core Razor提供语言服务。
ASP.NET Web Frameworks and Tools 2017 5.2.50921.0有关其他信息,请访问https://www.asp.net/
Azure应用服务工具v3.0.0 15.0.30915.0 Azure应用服务工具v3.0.0
Common Azure Tools 1.10提供由Azure移动服务和Microsoft Azure工具使用的公共服务。
JavaScript语言服务2.0 JavaScript语言服务
JavaScript Project System 2.0 JavaScript Project System
JavaScript UWP Project System 2.0 JavaScript UWP Project System
Merq 1.1.17-rc(cba4571)Command Bus,Event Stream and Async Manager for Visual Studio extensions.
Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017-v2.9.50719.1
Microsoft Continuous Delivery Tools for Visual Studio 0.3简化了Visual Studio IDE中持续生成集成和持续生成交付的配置。
Microsoft JVM Debugger 1.0支持将Visual Studio调试器连接到与JDWP兼容的Java虚拟机
Microsoft MI-Based Debugger 1.0支持将Visual Studio连接到MI兼容的调试器
Microsoft Visual Studio VC包1.0 Microsoft Visual Studio VC包
Mono Debugging for Visual Studio 4.7.4-pre(c2d89eb)支持使用Visual Studio调试Mono进程。
NuGet Package Manager 4.4.0 Visual Studio中的NuGet Package Manager。有关NuGet的更多信息,请访问http://docs.nuget.org/
SQL Server数据工具15.1.61707.200 Microsoft SQL Server数据工具
TypeScript www.example.com Visual Studio的TypeScript工具2.3.5.0 TypeScript tools for Visual Studio
Visual Studio代码调试适配器主机包1.0互操作层,用于在Visual Studio中承载Visual Studio代码调试适配器
Visual Studio Tools for Universal Windows应用程序15.0.27004.2002 Visual Studio Tools for Universal Windows应用程序允许您构建单一通用应用程序体验,该体验可覆盖运行Windows 10的所有设备:手机、平板电脑、PC等。它包含Microsoft Windows 10软件开发工具包。
用于Visual Studio的IoT 1.0包,包含IoT组件
VisualStudio.Mac 1.0 Mac Extension for Visual Studio
WebJobs Tools v1.0.0 15.0.30923.0 WebJobs Tools v1.0.0
Xamarin www.example.com(fe36bec)Visual Studio扩展,用于支持Xamarin. iOS和Xamarin.Android的开发。4.7.10.22 (fe36bec) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin. Android SDK www.example.com(HEAD/7a6a056e8)Xamarin. Android参考程序集和MSBuild支持. 8.0.0.33 (HEAD/7a6a056e8) Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin. iOS和Xamarin.Mac SDK www.example.com(9a9f054)Xamarin. iOS和Xamarin.Mac参考程序集和MSBuild支持。11.2.0.8 (9a9f054) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
我在这里报告了这个问题https://developercommunity.visualstudio.com/content/problem/131554/dispatcher-processing-has-been-suspended-but-messa.html
我在这里填充了一个bug轨道https://connect.microsoft.com/VisualStudio/feedback/details/3142780

5sxhfpxr

5sxhfpxr1#

卸载此网上银行插件后,问题消失了:

huus2vyu

huus2vyu2#

刚开始导航到URL,解决了我。

public MainWindow()
{
    InitializeComponent();
    browser.Navigate("about:blank");
}
vtwuwzda

vtwuwzda3#

我遇到了这个问题,最近出现在一个WPF应用程序上,这个应用程序已经存在多年了(更多细节在我的问题中)。
简而言之,在Release配置中启用Prefer 32 bit为我们解决了这个问题。也使它更快。
完全不知道为什么!

相关问题