除了processmessage,还有什么我可以用来保持程序的响应? [英] Anything else I can use to keep program responsive besides processmessage?

查看:99
本文介绍了除了processmessage,还有什么我可以用来保持程序的响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以运行很长时间扫描数据库的应用程序。

在此过程中,我通过使用processmessage来保护我的程序。

此过程被触发我的进度条被更新并被包含。

这个工作正常是大多数情况,但是当数据库变大时,进度条跳上1%就需要更长的时间,直到那个时候,程序才变得没有反应

I have an application that can run for quite a long time scanning a database.
During this process I keep my program responsive by using processmessage.
This processmessage is triggered when my progress bar is updated and inc'ed.
This works fine is most cases, but when the databases get larger it takes longer for the progress bar to jump up 1%, the program becomes unresponsive until that time.

除了进程消息之外,还有另一种方法来保持我的程序生活吗?

Is there another way to keep my program alive besides processmessages?

推荐答案

多线程是答案。一个标准的Delphi应用程序基本上是一个单线程的应用程序,可以一次做一件事。因此,gui lockup,它不能保持敏感,如果它正在做其他事情。

Multi threading is the answer. A standard Delphi application is basically a single threaded application that can do one thing at a time. Hence the gui lockup, it can't remain responsive if it's doing something else.

如果你想有一个响应的gui,同时做重力,你需要在单独的线程或线程上重起来。这样你的主线程可以确保你有一个响应程序,并且工作线程做得很重。
这对于重型数据库工作非常有用,但是对于例如下载文件或者例如远程服务器的答案可能需要很长时间的情况,这样做很好。

If you want to have a responsive gui and do heavy lifting at the same time, you need to have the heavy lifting in a separate thread or threads. This way your main thread can make sure you have a responsive program and the worker threads do the heavy lifting. This works nice for heavy database work but also for for instance the downloading of files or situations where an answer of for instance a remote server can take a long time.

但是这个答案可能会给你更多的问题,因为解释如何使用多线程将是太大的解释这个问题。

But this answer will probably give you more questions then answers because to explain HOW to use multi threading would be too big of an explanation for this question.

另一件事尽管如此:对数据库代码进行了长时间的研究。如何从数据库中检索记录,数据库中是否存在良好的索引等等。在开始考虑多线程之前,您可以通过优化此代码来实现精确的速度改进。

One other thing though: have a long and hard look at your database code. How are you retrieving records from the database, are there good indexes on the database etc. etc. etc. You can get insane speed improvements by optimizing this code before you have to start thinking about multi threading.

我发现了以下资源: http://thaddy.co.uk/threads/ 您可以下载图片: http://cc.embarcadero.com/item/14809 非常有用的线程教程。

I've found the following resource: http://thaddy.co.uk/threads/ which you can download with pictures at: http://cc.embarcadero.com/item/14809 to be very usefull threading tutorial.

这篇关于除了processmessage,还有什么我可以用来保持程序的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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