WPF:Windows窗体应用程序交互导致奇怪错误

WPF:Windows窗体应用程序交互导致奇怪错误,wpf,thread-safety,Wpf,Thread Safety,我有一个windows.forms应用程序,它在按钮单击事件处理程序上创建WPF窗口。它在WPF窗口实例上调用“Show”方法 当父windows.forms窗口位置更改时(WPF窗口在视觉上跟随windows.forms窗口固定),WPF窗口开始侦听父窗口事件并尝试调整自身大小(设置left、top、width、height属性) 一切正常,但由于某些原因,我偶尔会收到未处理的SEH异常弹出窗口: at System.Windows.Forms.UnsafeNativeMethods.D

我有一个windows.forms应用程序,它在按钮单击事件处理程序上创建WPF窗口。它在WPF窗口实例上调用“Show”方法

当父windows.forms窗口位置更改时(WPF窗口在视觉上跟随windows.forms窗口固定),WPF窗口开始侦听父窗口事件并尝试调整自身大小(设置left、top、width、height属性)

一切正常,但由于某些原因,我偶尔会收到未处理的SEH异常弹出窗口:

   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm) ...
它不时出现,很难找出我做错了什么

我还注意到,WPF窗口和Windows.Forms窗口运行在不同的线程上

有什么想法吗?

让我自己回答

最后,我停止了与Windows.FormWPF窗口集成的斗争,将WPF窗口重构为WPF用户控件,并将其放入标准的Windows.Forms ElementHost(只是将组件从工具箱拖到包装器Windows.Form实例)

现在一切都好了