UI线程都在运行的消息泵和执行代码? [英] UI Thread both running message pump AND executing code?

查看:221
本文介绍了UI线程都在运行的消息泵和执行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WinForms UI线程在运行的消息泵,通过调用 Application.Run 的责任。由消息泵我的意思是一个无限循环,不断从队列中拉出来的消息。

The UI thread in Winforms have the responsibility of running the message pump, by calling Application.Run. By message pump I mean an endless loop that keeps pulling messages out from the queue.

所以,现在是我的问题,如何能在UI线程执行也是一个代码块时前。点击处理程序被触发?它应该是忙于消息泵,并没有能够执行的代码?

So now is my question, how can the UI thread also execute a block of code when ex. a click handler is triggered? It should be busy with the message pump, and not able to execute the code?

推荐答案

这需要超时处理的消息泵来处理消息,因为这是同步从消息泵(通过单击事件)调用。

It takes time out of processing the message pump to handle the message, as this is synchronously called from the message pump (via the click event).

这就是为什么昂贵的代码可能导致用户界面挂起。

This is why expensive code can cause the UI to hang.

这篇关于UI线程都在运行的消息泵和执行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆