• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Controls don't finish rendering before next code block starts executing

I'm having a rather serious and consistent problem in my windows forms.

It seems that whenever I build a form of even moderate complexity, and then try to update any of the controls on the surface, quite often, the controls do not fully render themselves before the next code block starts executing.  As a simple example:

void DisplayProblem() {
     form.status = "starting long method";
     DoLongMethod();
     form.status = "done";
}

whenever I run code this way, the forms status bar will not fully render its update BEFORE the long method starts, which is exactly what I need it to do.

Here's another example:

void ShowFormThingy() {
     form1.Show();
     DoLongMethod();
}

This one is even more noticable.  What will happen is the form will start to render, get through rendering about half of its surface (just enough rendering to appear totally broken), then begin executing the long method, all the while the form is frozen in its half rendered state.

What can I do to ensure the form is fully rendered BEFORE moving on to the next statement?


0
rmirabelle
Asked:
rmirabelle
  • 2
1 Solution
 
AlexFMCommented:
void DisplayProblem() {
     form.status = "starting long method";
     Application.DoEvents();
     DoLongMethod();
     form.status = "done";
}
0
 
AlexFMCommented:
void ShowFormThingy() {
     form1.Show();
     Application.DoEvents();
     DoLongMethod();
}
0
 
rmirabelleAuthor Commented:
I just figured this one out on my own right after submitting the question - the call to do events flushes the current message queue, eh?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now