0
在cmd上執行命令時,我試圖激活進度環,當命令執行時按鈕保持按下狀態,當進程完成時釋放按鈕,但當進程仍然處於活動狀態時,我無法啓動進程環運行,似乎像WaitForExit不適合我。Mahapps ProgressRing WPF C#
private void Button_Click(object sender, RoutedEventArgs e)
{
if (ComboBox.Text == "")
{
MessageBox.Show("Select a drive");
}
else
{
try
{
ProgressRing.IsActive=true;
Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine("attrib -r -s -h " + ComboBox.Text + "*.* /s /d");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
ProgressRing.IsActive=false;
}
catch (Exception i)
{
Console.WriteLine("{0} Exception caught.", i);
MessageBox.Show("Error");
}
}
}
謝謝你它的工作非常好!我試圖讓一個線程設置進度IsActive屬性,而不是執行cmd命令 –