473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A question about Threads

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

Sep 13 '07 #1
11 1073
bob
On Thu, 13 Sep 2007 14:31:51 -0700, Dom <do********@gmail.comwrote:
>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
Sep 13 '07 #2
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.
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
Sep 14 '07 #3
Dom wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 14 '07 #4
Göran Andersson wrote:
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
Sep 14 '07 #5
Simply define a minimum timespan your popup window
is shown. For example 1.5sec.

Sep 14 '07 #6
Roman Wagner wrote:
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
Sep 14 '07 #7
Peter Duniho wrote:
Göran Andersson wrote:
>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
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.

--
Göran Andersson
_____
http://www.guffa.com
Sep 14 '07 #8
Dom wrote:
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.
Sep 14 '07 #9
Dom
On Sep 13, 5:31 pm, Dom <dolivas...@gmail.comwrote:
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

Sep 14 '07 #10
Göran Andersson wrote:
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
Sep 14 '07 #11
Dom wrote:
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
Sep 14 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nick Marden | last post by:
I am trying to use threads::shared to make a thread-safe object. It appears to be the case that copying a blessed-then-shared reference to another shared variable keeps the underlying structure...
5
by: Peter Kirk | last post by:
Hi, I see in the ThreadPool documentation that the pool has a default limit of 25 threads. Is it correctly understood that this limit is for my entire application? So if I have several...
2
by: Servé Lau | last post by:
I have been rewriting a C++ isapi into a C# asp.net application, but because it was my first one and created within a tight schedule I have some questions to make sure if I did it right. 1. Does...
3
by: Henri | last post by:
1) Do Shared methods always need to be synchronised to be thread-safe? 2) Why must SyncLock be used with a reference type? I can't get the relation between threads and a type. Thanks for your...
6
by: Roka | last post by:
Hi all. I'm reading a program which used the sentence below: #define NUM_THREADS 10 ... ... int rand_num; rand_num = 1+ (int) (9.0 * rand() / (RAND_MAX + 1.0)); sleep(rand_num); ... ......
3
by: michdoh | last post by:
Hi All I'm looking for some help on creating a basic multi threaded application. i'n new to threads in this environment so for test purposes I've produced a very basic program. (which doesn't...
7
by: Diego F. | last post by:
Hello. I have a doubt about multi-threading, if it is or not the best way to achieve the following: I have a server application that listens a port through a socket. A client will send messages...
18
by: Jon Slaughter | last post by:
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than...
5
by: FP | last post by:
Hi, i'm currently developing a class to communicate with a serial device,using the SerialPort component. Basically,the main application will interact with this class through its method "Call",the...
19
by: =?ISO-8859-1?Q?Nordl=F6w?= | last post by:
I am currently designing a synchronized queue used to communicate between threads. Is the code given below a good solution? Am I using mutex lock/unlock more than needed? Are there any resources...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.