在长时间运行的任务期间保持 GUI 响应 [英] Keeping GUIs responsive during long-running tasks

查看:32
本文介绍了在长时间运行的任务期间保持 GUI 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序执行一些 CPU 密集型处理时保持 GUI 响应是有效 GUI 编程的挑战之一.

Keeping the GUI responsive while the application does some CPU-heavy processing is one of the challenges of effective GUI programming.

这里有一个关于如何在 wxPython 中执行此操作的很好的讨论.总结一下,有3种方式:

Here's a good discussion of how to do this in wxPython. To summarize, there are 3 ways:

  1. 使用线程
  2. 使用 wxYield
  3. 将工作分块并在 IDLE 事件处理程序中完成

发现哪种方法最有效?也欢迎来自其他框架(如 Qt、GTK 或 Windows API)的技术.

Which method have you found to be the most effective ? Techniques from other frameworks (like Qt, GTK or Windows API) are also welcome.

推荐答案

线程.它们是我一直追求的目标,因为您可以在您需要的每个框架中做到这一点.

Threads. They're what I always go for because you can do it in every framework you need.

一旦您习惯了在一种语言/框架中的多线程和并行处理,您就可以熟练使用所有框架.

And once you're used to multi-threading and parallel processing in one language/framework, you're good on all frameworks.

这篇关于在长时间运行的任务期间保持 GUI 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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