【问题标题】:WPF: Windows Forms application interaction causes strange errorsWPF:Windows 窗体应用程序交互导致奇怪的错误
【发布时间】:2011-01-08 17:23:04
【问题描述】:

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

当父 windows.forms 窗口位置改变时,WPF 窗口开始监听父窗口事件并尝试调整自身大小(设置 left、top、width、height 属性)(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 窗口在不同的线程上运行。

有什么想法吗?

【问题讨论】:

    标签: wpf thread-safety


    【解决方案1】:

    让我自己回答。

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

    现在一切正常!

    【讨论】:

      猜你喜欢
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      相关资源
      最近更新 更多