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

时间:2011-01-08 17:23:05

标签: wpf thread-safety

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

当父窗口窗口位置发生变化时,WPF窗口开始侦听父窗口事件并尝试调整自身大小(设置左,顶部,宽度,高度属性)(WPF窗口可视化跟随Windows.Forms窗口,因为它被固定)。

一切正常但由于某种原因我偶尔会收到SEH exception was unhandled弹出窗口:

   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窗口在不同的线程上运行。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

让我自己回答。

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

现在一切都好!