Application.Idle event not firing in WPF application

﹥>﹥吖頭↗ 提交于 2019-11-27 07:03:37

问题


I am using a third-party Windows Forms control that performs some actions "delayed" using the Application.Idle event.

Now that we're moving our application to WPF, these actions stopped working. I've found that the System.Windows.Forms.Application.Idle event is not raised as expected.

How can I get the Idle event to fire in a WPF application so that I can continue to use that third-party control (within a WindowsFormsHost)? It is not possible to modify the Windows Forms control.


回答1:


You should read this page on MSDN which describes the message loop behavior in a WPF application. In particular it looks like the ComponentDispatcher class can be used to catch a ThreadIdle event which would roughly correspond to the Windows Forms Application.Idle event.

You could then presumably use the System.Windows.Forms.Application.RaiseIdle method to raise the Idle event as the component expects.




回答2:


If you are using a WPF Application, you are actually no longer using the System.Windows.Forms.Application class to run your application, even if your application contains a Windows Forms Control.

Instead, you are using the System.Windows.Application class (different namespace).



来源:https://stackoverflow.com/questions/2344398/application-idle-event-not-firing-in-wpf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!