如何编写一个只绘制Text和setPixel而不进入main_loop的wxRuby程序?
我想编写一个程序,不断计算数字,并在窗口画布上绘图,包括绘制文本和设置像素。因此程序可能无法进入事件循环(main_loop),因为这将停止数字的计算。
有没有一种方法可以在没有事件循环的情况下绘制项目?
或者,应该创建一个线程,以便一个线程执行计算,并由一个线程处理窗口的事件循环?
I want to write a program that will constantly compute numbers, and draw on the window canvas, including drawing text and setting pixels. So the program probably cannot go into an event loop (the main_loop), because that will stop the computation of numbers.
Is there a way just to draw the items without an event loop?
Or, should a thread be created, so that one thread will do the computation, and one thread handles the window's event loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于必须进行长时间计算的基于事件的程序,其一般策略是以下之一:
第一种方法如果您能管理的话,这是理想的选择。我个人偏好第三种方法。 IMO 线程应该尽可能避免,除非你完全理解线程编程(即使如此,我通常仍然建议使用单独的进程)。
The general strategy for event-based programs that must do long calculations is one of the following:
The first method is ideal if you can manage it. My personal preference then goes to the third method. IMO threads should be avoided if at all possible, unless you fully grok threaded programming (and even then I still usually recommend a separate process).