我目前正在編寫一個輕量級程序,它將許多命令行和其他外部進程整合到一個應用程序中。外部進程的進度條
目前,我面臨着使用系統信息過程提取系統信息的挑戰。
我已經成功編寫了按鈕來調用系統信息進程,並將輸出重定向到文本字段。
我現在試圖在我的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