A question about Threads

D

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
 
B

bob

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
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
 
P

Peter Duniho

Dom said:
[...]
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.

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
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Dom said:
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

A common solution is to use a timer so that you only show the
popup/message when the task is taking more than three seconds.
 
P

Peter Duniho

Göran Andersson said:
A common solution is to use a timer so that you only show the
popup/message when the task is taking more than three seconds.

That's not a very good solution IMHO. All it does is shift the
undesired behavior from tasks that take very little time (say, half a
second or less) to tasks that take three seconds plus very little time.

Unless some very large proportion of the scenarios involve tasks that
take less time than the threshold (eg three seconds), meaning that you
can at least shift the undesired behavior to a much lower frequency,
it's not really an improvement.

Even if you can reduce the frequency of the undesired behavior, it would
be better to just eliminate it altogether.

Pete
 
R

Roman Wagner

Simply define a minimum timespan your popup window
is shown. For example 1.5sec.
 
P

Peter Duniho

Roman said:
Simply define a minimum timespan your popup window
is shown. For example 1.5sec.

Yup...that resolves the blinking problem. But then it adds an arbitrary
minimum amount of time that the task will take, forcing the user to wait
for some time (like 1.5 seconds) even if the task completes in less time.

This may be acceptable in some situations...something the user doesn't
have to do very often, for example. But I know I'd get a bit annoyed if
I found myself waiting even an extra second or so on a regular basis.
More generally, users can easily detect even sub-second delays if they
occur frequently; it's surprising how little of a delay turns the user
experience into an impression of "unresponsive".

No, I still think it's better to either try to predict the duration of
the task and use that as a "show or not" test, or to just put the
feedback somewhere that a momentary display will not be so jarring.

Pete
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Peter said:
That's not a very good solution IMHO. All it does is shift the
undesired behavior from tasks that take very little time (say, half a
second or less) to tasks that take three seconds plus very little time.

Unless some very large proportion of the scenarios involve tasks that
take less time than the threshold (eg three seconds), meaning that you
can at least shift the undesired behavior to a much lower frequency,
it's not really an improvement.

Even if you can reduce the frequency of the undesired behavior, it would
be better to just eliminate it altogether.

Pete

Yes, of couse it would be better if you know beforehand exactly how long
the task will take, but in most situations you don't.

You can see this behaviour for example in Photoshop. When an action
takes longer than three seconds, you get a progress bar in the middle of
the screen.
 
C

Chris Shepherd

Dom said:
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.

Taking a different approach, with DataGridViews I just have a simple
method that blanks the grid and puts a "retrieving records" message in
it. I'm sure you could work something similar with a ListView.

I try to avoid popping things up like the plague.

Chris.
 
D

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

I think I'm going to take the simplest approach. I'll get rid of the
threads, get rid of the pop-up, and just turn the mouse into an hour-
glass until the job gets done. That will give me a blinking mouse in
some cases, but that's better than a blinking window.

Dom
 
P

Peter Duniho

Göran Andersson said:
Yes, of couse it would be better if you know beforehand exactly how long
the task will take, but in most situations you don't.

True, which is why I proposed not having a dialog pop up at all. Only
in very specific situations is it possible to predict the length of the
task with any accuracy.

If you start with the design requirement that a dialog pop up, the
problem is very difficult to solve. IMHO, the better solution is to
change the design requirement to make it an easier problem.
You can see this behaviour for example in Photoshop. When an action
takes longer than three seconds, you get a progress bar in the middle of
the screen.

True, and it suffers the exact problem I mention: for actions longer
than its threshold for display, if those actions are only just longer,
the progress display still blinks, just as it would if it were displayed
immediately.

Pete
 
P

Peter Duniho

Dom said:
I think I'm going to take the simplest approach. I'll get rid of the
threads, get rid of the pop-up, and just turn the mouse into an hour-
glass until the job gets done. That will give me a blinking mouse in
some cases, but that's better than a blinking window.

I don't think you really want to get rid of the thread. That's what
allows your UI to be responsive even while the task is proceeding.

Setting the mouse cursor to the wait cursor is, of course, a fine idea. :)

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top