我目前正在编写一个轻量级程序,它将许多命令行和其他外部进程整合到一个应用程序中。外部进程的进度条
目前,我面临着使用系统信息过程提取系统信息的挑战。
我已经成功编写了按钮来调用系统信息进程,并将输出重定向到文本字段。
我现在试图在我的WPF窗口底部有一个进度条,因为它需要一些时间来加载系统信息。
由于我不知道从外部过程中获得准确持续时间的方法,因此我试图使用“选取框”样式。
我一直在下面的例子在这里stackoverflow(Windows Forms ProgressBar: Easiest way to start/stop marquee?),以及其他网站,但还没有能够确定在哪里把代码,以便进度条滚动while systeminfo运行时,并停止完成。
我目前的代码(没有progressbar1.Style = ProgressBarStyle.Marquee;
)在下面。
任何有关在何处放置代码或使用何种语法的建议都将不胜感激。先谢谢你!
private void btnSystemInfo_Click(object sender, RoutedEventArgs e)
{
// Get system info
Process info = new Process();
info.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
info.StartInfo.FileName = "C:\\Windows\\system32\\systeminfo.exe";
info.StartInfo.Arguments = "-S " + context;
info.StartInfo.UseShellExecute = false;
info.StartInfo.CreateNoWindow = true;
info.StartInfo.RedirectStandardOutput = true;
info.Start();
string infoOutput = info.StandardOutput.ReadToEnd();
info.WaitForExit();
// Write to the txtInfo text box
txtInfo.Text = "System Info: " + infoOutput;
txtInfo.Foreground = Brushes.Black;
txtInfo.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
// Switch to the info tab
tabControl.SelectedIndex = 3;
}
谢谢哈里斯哈桑!这是我一直在寻找的! – PsiLentRain