473,385 Members | 1,311 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,385 software developers and data experts.

Question about no response of main Form

Hi all,

I ran into a headache problem. I have a windows form with a progress
bar on it. Then I new a thread to do calculation for a long time. I
want the progress bar to show the calculation progress. So I use a
shared variable in calculation thread to allow main thread read it
periodically in order to show the progress. Quesion comes out. If I
just wait and don't make any operation during the whole calculation,
the main form is OK, with progress bar increased step by step. But If
I click other application or just drag the form, main form will have
no response until the calculation finished. At first I think that
maybe the calculation is too tight to be a circle. So I add several
sleep() in it. But this method is of no use. I have no idea this time.
Anybody can help me? Thanks in advance!

Jun 20 '07 #1
2 2373
I ran into a headache problem. I have a windows form with a progress
bar on it. Then I new a thread to do calculation for a long time. I
want the progress bar to show the calculation progress. So I use a
shared variable in calculation thread to allow main thread read it
periodically in order to show the progress. Quesion comes out. If I
just wait and don't make any operation during the whole calculation,
the main form is OK, with progress bar increased step by step. But If
I click other application or just drag the form, main form will have
no response until the calculation finished. At first I think that
maybe the calculation is too tight to be a circle. So I add several
sleep() in it. But this method is of no use. I have no idea this time.
Anybody can help me? Thanks in advance!
Does the main thread launch your worker thread and then immediately enter
some loop to periodically check the shared variable? It certainly appears
that way and if so then it's not correct. You can Google for "Windows
message loops" to understand why but to correct the problem you may want to
have a look at the "BackgroundWorker" class. It's designed to handle exactly
what you're trying to do although you can still resort to other conventional
means if you want (once you read up on Windows message loops but why bother
when "BackgroundWorker" makes life easier).
Jun 20 '07 #2
On Jun 21, 12:06 am, "Larry Smith" <no_spam@_nospam.comwrote:
I ran into a headache problem. I have a windows form with a progress
bar on it. Then I new a thread to do calculation for a long time. I
want the progress bar to show the calculation progress. So I use a
shared variable in calculation thread to allow main thread read it
periodically in order to show the progress. Quesion comes out. If I
just wait and don't make any operation during the whole calculation,
the main form is OK, with progress bar increased step by step. But If
I click other application or just drag the form, main form will have
no response until the calculation finished. At first I think that
maybe the calculation is too tight to be a circle. So I add several
sleep() in it. But this method is of no use. I have no idea this time.
Anybody can help me? Thanks in advance!

Does the main thread launch your worker thread and then immediately enter
some loop to periodically check the shared variable? It certainly appears
that way and if so then it's not correct. You can Google for "Windows
message loops" to understand why but to correct the problem you may want to
have a look at the "BackgroundWorker" class. It's designed to handle exactly
what you're trying to do although you can still resort to other conventional
means if you want (once you read up on Windows message loops but why bother
when "BackgroundWorker" makes life easier).
Hi Larry,

BackgroundWorker, really cool. That works!

I think over for my periodical checking status in main thread, that
should be blocked in main form. But what about using a timer, I
haven't tried that. My intuition is that timer maybe OK. Anyway, I'll
spend my time in studying Windows message loops after finishing. Thank
you very much!

Jun 21 '07 #3

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

Similar topics

17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
2
by: Drew Stoddard | last post by:
We are working in C#/Winforms and are using asynchronous client-side web service calls (the Begin... and End... methods supplied by the web reference creation). Many of these calls are contained...
6
by: William Bradley | last post by:
I have a production table and its accompanying form. There can be up to ten ingredients in what is produced. The ingredients are obtained from the incoming goods table which supplies the two...
7
by: Alice | last post by:
Hi, In my program, the user can navigate to many different forms. When they go to the next form, I want the form they have left to close. However, the forms aren't closing. Can anyone tell me...
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...
13
by: Jordan | last post by:
All, I have a UI form calling a class object that contains a timer that routinely draws intensive information to the screen (~30 fps). The drawing is invoked on the main UI thread. I need the...
1
by: Kandiman | last post by:
Hiya, i made a asp page, and one of my divs (as a include) is as below. the problem is if the main page is resubmitted, i get logged out again?... heres the code.. i think its on the value=true...
12
by: bpw22az | last post by:
Bare with me guys. I will try and make this short and to the point. I have a website that allows students to check their admission status by submitting their email address which in turn sends them...
1
by: bruce | last post by:
Hi. Got a test web page, that basically has two "<html" tags in it. Examining the page via Firefox/Dom Inspector, I can create a test xpath query "/html/body/form" which gets the target form for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...

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.