tags:

views:

23

answers:

3

On a button click, I make several changes to form elements (hiding some, showing some, bringing some to front, etc.). After those form element changes are made, I run an external process with a Process.Start(). However, even those those form element layout changes are sequentially coded before the Process.Start() call, they're not being executed/displayed BEFORE my Process.Start().

How do you force a flush of these layout changes that seem to be buffered?

A: 

Try either running the .Refresh method before the process.Start, or run Process.Start in a separate thread, such as:

System.Threading.ThreadPool.QueueNewWorkerItem(new System.Threading.WaitCallback(StartProcess));

void StartProcess(object state)
{
    Process.Start(...);
}

By putting the start in a background thread, you allow .NET to update the UI before items in the background thread run. If the Process.Start is in the same thread as the UI, then the UI cannot refresh until all processes in that thread have finished running.

Russ
Russ, thanks -- does my mainFormName.ActiveForm.Update() [which works for me now] have any short-sightedness I'm not seeing?
Neil
No--whatever you find works for you--use.
Russ
A: 

Found answer..

mainFormName.ActiveForm.Update();

Bang bang.

Neil
+1  A: 

You could try the Control.Invalidate(true) function on the control you want to be redrawn.

Here is a good post about the difference between Refresh, Update, and Invalidate

Based on the Post, I think you would want to use Refresh over Update to invalidate, then immediately update the control

SwDevMan81
Update() is the right one here.
Hans Passant
@Hans - Would that be because the OP has already invalidated the controls? So using Refresh to invalidate would be redundant...
SwDevMan81
Right, Refresh forces a repaint even if the control doesn't need it.
Hans Passant