开发者

How can I flush buffer of form object properties BEFORE a Process.Start is executed?

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(). Howev开发者_如何转开发er, 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?


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


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.


Found answer..

mainFormName.ActiveForm.Update();

Bang bang.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜