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?


LVL 1
rmirabelleAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.