Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows form freezes

Status
Not open for further replies.

djam

Technical User
Nov 15, 2002
223
CA
I have a windows form, when the submit button is pressed the form has to wait until the application finishes processing before it can continue. While the user waits, they might drag another window over my form, this causes the form to blank out and not repaint itself because the application is still processing. How can i fix this. I want the form to repaint. Do I need to have mulitple threads? Or is there something that I can set on the form to always repaint?

thanks

" ahhh computers, how they made our lives much simpler ;) "
 
Call :
Code:
this.Invalidate(true);
this.Update();
where this is the Form object to causes a paint message to be sent to the control and its child controls.
-obislavu-
 
where would I put this call?

" ahhh computers, how they made our lives much simpler ;) "
 
Forms in .net are single-threaded, unless you create some other threads otherwise. So when you go do some lengthy operation on the form's thread, the thread is not able to repaint the form.

If you want the "clean" look of the form repainting itself when another window is dragged across it, you'll need to create a thread to do your operation on, and make sure you write code to prevent any recursion (it may be possible for the user to click other buttons while the operation is in progress, which would cause problems).

There's two schools of thought on handling the "worker thread from a form" problem:
1) Disable all the controls on the form that would lead to bad things happening
2) When they do click on another control, show a pop-up asking them if they want to cancel the background operation.

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top