关于线程的问题 [英] A question about Threads

查看:77
本文介绍了关于线程的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要的:


1.用户点击按钮查看Access

文件中所有表的列表。

2.线程启动以获取表格列表。

3.弹出一个模态窗口,上面写着请稍候......,所以用户知道

应用程序没有死亡。

4.线程完成后,模态窗口消失,并且

listview充满了表格。


我已经完成了所有这些工作。问题是在大多数情况下,

访问文件只有几个表,所以模态窗口是一个恼人的小眨眼。有没有办法显示窗口只有当线程需要很长时间才会显示窗口,否则不显示它?我已经提出了一些解决方案,但没有一个真正有效。


Dom

Here''s what I want:

1. A user clicks on a button to see a list of all tables in an Access
file.
2. A thread starts up to obtain the list of tables.
3. A modal window pops up saying "Please wait ...", so the user knows
the application didn''t just die.
4. When the thread is done, the modal window disappears, and a
listview is filled with the tables.

I have all this working fine. The problem is that on most occasions,
the access file only has a few tables, so the modal window is an
annoying little blink. Is there some way to show the window only if
the thread is taking a long time, and not show it otherwise? I''ve
come up with a few solutions, but none really work.

Dom

推荐答案

2007年9月13日星期四14:31:51 -0700,Dom< do ******** @ gmail.comwrote:
On Thu, 13 Sep 2007 14:31:51 -0700, Dom <do********@gmail.comwrote:

>这就是我想要的:

1。用户单击按钮以查看Access
文件中所有表的列表。
2。线程启动以获取表格列表。
3。弹出一个模态窗口,上面写着请稍候......,因此用户知道应用程序并没有死亡。
4。当线程完成后,模态窗口消失,并且表格中充满了表格。

我已经完成了所有这些工作。问题是,在大多数情况下,访问文件只有几个表,所以模态窗口是一个恼人的小眨眼。有没有办法显示窗口只有线程花了很长时间才会显示,否则不显示?我已经提出了一些解决方案,但没有一个真正有效。

Dom
>Here''s what I want:

1. A user clicks on a button to see a list of all tables in an Access
file.
2. A thread starts up to obtain the list of tables.
3. A modal window pops up saying "Please wait ...", so the user knows
the application didn''t just die.
4. When the thread is done, the modal window disappears, and a
listview is filled with the tables.

I have all this working fine. The problem is that on most occasions,
the access file only has a few tables, so the modal window is an
annoying little blink. Is there some way to show the window only if
the thread is taking a long time, and not show it otherwise? I''ve
come up with a few solutions, but none really work.

Dom



嗨Dom,

如果工作线程很长,则从工作线程中提出一个事件。

假设你有一些经济的方法来计算工作长度。

将模态Box调用放入事件处理程序。

如果你使用backgroundworker线程,它有进度事件

设施内置

Bob

Hi Dom,
Raise an event from the worker thread if it is going to be a long job.
Assuming you have some economical way of figuring out the job length.
Put the modal Box call in the eventhandler.
If you use a backgroundworker thread, it has the progress event
facility built in
Bob


Dom写道:
Dom wrote:

[...]

我有这一切都很好。问题是在大多数情况下,

访问文件只有几个表,所以模态窗口是一个恼人的小眨眼。有没有办法显示窗口只有当线程需要很长时间才会显示窗口,否则不显示它?我已经提出了一些解决方案,但没有一个真正奏效。
[...]
I have all this working fine. The problem is that on most occasions,
the access file only has a few tables, so the modal window is an
annoying little blink. Is there some way to show the window only if
the thread is taking a long time, and not show it otherwise? I''ve
come up with a few solutions, but none really work.



定义线程需要很长时间。如果您只是等待预定时间的某些时间然后显示对话框,那么在显示对话框时,您将始终运行完成任务的风险

,导致它

眨眼。


另一方面,如果你能想出某种启发式的话,那么
预测会持续多长时间任务将采取,然后你可以显示对话框

只有当规则告诉你任务需要足够长的时间才能证明它是正确的。


我个人,我为了告诉我

a任务需要一段时间,我不会成为新对话框的忠实粉丝。相反,使用已经存在的UI:您的ListView控件及其存在的形式。

将一些占位符放在它上面,显示文字说请

等待......或等价物(例如,进度条或微调器或

之类的东西),向ListView添加一些相同的东西,或者

只是将ListView本身更新为结果返回。恕我直言,

后者可能是最好的解决方案,因为用户立即得到早期结果
。但是,如果延迟是与

数据库的初次接触,您可能没有任何早期结果,在这种情况下,

其他技术之一是更好。


Pete

Define "the thread is taking a long time". If you simply wait for some
predetermined time and then display the dialog, you will always run the
risk of the task completing just as you display the dialog, causing it
to blink.

On the other hand, if you can come up with some sort of heuristic that
predicts how long the task will take, you can then display the dialog
only when that rule tells you the task will take long enough to justify it.

Personally, I''m not a big fan of new dialogs popping up just to tell me
a task is going to take awhile. Instead, use the UI that already is
there: your ListView control and the form in which it exists. Either
put some sort of placeholder over it displaying text saying "Please
wait..." or the equivalent (for example, a progress bar or spinner or
something like that), add something to the ListView saying the same, or
just update the ListView itself as the results are returned. IMHO, the
latter is perhaps the best solution as the user gets the "early results"
immediately. Though, if the delay is in the initial contact with the
database, you may not have any "early results", in which case one of the
other techniques is better.

Pete


Dom写道:
Dom wrote:

Here这就是我想要的:


1.用户点击一个按钮,查看Access

文件中所有表的列表。

2.线程启动以获取表格列表。

3.弹出一个模态窗口,说请稍候......,这样用户就知道了/>
应用程序没有死。

4.线程完成后,模态窗口消失,并且

listview被填充桌子。


我把这一切都搞好了。问题是在大多数情况下,

访问文件只有几个表,所以模态窗口是一个恼人的小眨眼。有没有办法显示窗口只有当线程需要很长时间才会显示窗口,否则不显示它?我已经提出了一些解决方案,但没有一个真正有效。


Dom
Here''s what I want:

1. A user clicks on a button to see a list of all tables in an Access
file.
2. A thread starts up to obtain the list of tables.
3. A modal window pops up saying "Please wait ...", so the user knows
the application didn''t just die.
4. When the thread is done, the modal window disappears, and a
listview is filled with the tables.

I have all this working fine. The problem is that on most occasions,
the access file only has a few tables, so the modal window is an
annoying little blink. Is there some way to show the window only if
the thread is taking a long time, and not show it otherwise? I''ve
come up with a few solutions, but none really work.

Dom



一个常见的解决方案是使用一个计时器,这样你只需要在任务超过三秒时显示

弹出/消息。


-

G?跑Andersson

_____
http://www.guffa.com


这篇关于关于线程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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