473,396 Members | 2,002 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,396 software developers and data experts.

Threading Question: Keeping the main UI responsive?


Source:
------------
http://home1.inet.tele.dk/jbech/bina...eadingtest.zip (25K)

Scenario:
---------------
Main form with two listboxes, a textbox, a button, and a trackbar.

Clicking the button starts three new threads:
t1) Fill listbox1 with numbers in a loop. Each time a number is added
to the listbox, selected index is set to the new item and the listbox
is explicitly refreshed.
t2) Fill listbox2 with numbers in a loop. Each time ... (same as t1)
t3) Calculate Pi to 700 decimals and place the result in the textbox.

The trackbar is just there to test whether the UI responds to mouse
events.

Problem:
--------------
When running these three threads on a P4 with hyperthreading, there
are absolutely no problems. All threads seem to get an equal share of
time and the UI responds perfectly well.

Running the program on a Pentium M notebook (without hyperthreading,
of course), though, UI responsiveness is a hit or miss affair. Usually
a miss.

I suspect that the two listbox threads are taking too much time away
from the UI, as they are constantly updating the listboxes.

If I change the priority of the three threads to "BelowNormal" (as I
have done in the source I have linked to above), the UI responds just
fine on the Pentium M machine, but ...

Questions:
---------------
1) If I run the worker threads using the BelowNormal priority, won't
this
just mean that other applications (e.g. a video encoder) will preempt
my application completely?

2) Instead of running the worker threads at BelowNormal priority,
would it be possible to run the main UI at AboveNormal priority and
the worker threads at normal priority?

This is just a test. The sample code could be prettier. I am a .Net
newbie, coming from 8 years of classic VB.

Eventually, the goal is to send a query to a SQL Server and have a
worker thread populate a listview or grid with a - potentially - large
result, yet allow the user to terminate this process at any time.

Is there a "best practice" for accomplishing this sort of thing?

The difference between running the code on a single-processor vs.
a (sort of) multi-processor one was a bit of a wake-up call, so I
guess I'll make sure I test such code on both types of machine in
the future :)

TIA,

Joergen Bech

Nov 21 '05 #1
0 904

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

Similar topics

9
by: Edward | last post by:
Hello I hope someone could help me I'm trying to prevent code from running before the thread I created completes. Here's the code snippet DataTransformerWorker dtw = new...
17
by: Arun Kumar | last post by:
What is wrong with this code. All i am trying to test is 3 progressbar and one button. On buttonclick i create 3 threads and each thread calls a method which in turn updates the progressbar and it...
13
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that....
6
by: Matt Long | last post by:
I was wondering if any one could help me out with a threading question. Im developing an app which starts a thread, which in turn starts 4 of its own threads. If I call 'sleep' on the initial...
8
by: mmitchell | last post by:
I have a thread that does periodic database maintenance. While this process is going on I would like the rest of the application to hold off on accessing the database. I thought I could share a...
2
by: blueturtle | last post by:
Hi, I'm newbie to C#, and I would like to know what is the common solution to a problem that I encounter. The scenario: Performing a long task, without blocking the UI thread, so it will stay...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.