简体   繁体   English

在执行Process.Start之前,如何刷新表单对象属性的缓冲区?

[英]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(). 在更改了这些表单元素之后,我使用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(). 但是,即使那些表单元素布局更改在Process.Start()调用之前顺序编码,也不会在我的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. 您可以在要重绘的控件上尝试使用Control.Invalidate(true)函数。

Here is a good post about the difference between Refresh , Update , and Invalidate 是一篇有关RefreshUpdateInvalidate之间的区别的好文章

Based on the Post, I think you would want to use Refresh over Update to invalidate, then immediately update the control 基于Post,我认为您想使用Refresh over Update来使之失效,然后立即更新控件

Try either running the .Refresh method before the process.Start, or run Process.Start in a separate thread, such as: 尝试在process.Start之前运行.Refresh方法,或在单独的线程中运行Process.Start,例如:

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. 通过将开始放在后台线程中,可以允许.NET在后台线程中的项目运行之前更新UI。 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. 如果Process.Start与UI处于同一线程中,则在该线程中的所有进程完成运行之前,UI无法刷新。

Found answer.. 找到答案..

mainFormName.ActiveForm.Update(); mainFormName.ActiveForm.Update();

Bang bang. 嘭嘭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可以在IIS上同时执行Process.Start - Can Process.Start Be Executed concurrently on IIS 如何在继续之前强制Process.Start()完成? - How do I force Process.Start() to complete before proceeding? 在尝试Process.Start()之前,如何以编程方式检查文件关联存在的文件? - How can I programmatically check file that a file association exists before attempting to Process.Start() it? 如何使用Process.Start启动管道并重定向命令? - How can I launch pipes and redirects commands with Process.Start? Process.Start(对象)不起作用 - Process.Start(object) not working 在process.start();之前检查该进程是否存在。 - Check if the process exists before process.start(); 当我使用Process.Start()运行该程序时,如何强制另一个程序不显示任何对话框 - How can I force another program to not show any dialog when I run it with Process.Start() 如果我具有洪流的URL,如何使用Process.Start()“启动”它? - If I have the URL of a torrent, how can I just “launch” it using the Process.Start()? 如何在 C# windows 应用程序的表单加载事件中的 process.start("notepad.exe") 之前播放 windows 媒体播放器 - how to play windows media player before the process.start("notepad.exe") in form load event in C# windows app 使用 Process.Start 时无法登录 Skype - Can't log to Skype when I use Process.Start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM