我有一個使用ST-LINK_CLI.exe將固件編程到ST-LINK的應用程序。進程運行時無法顯示文本c#WPF
用戶選擇一個固件,按下啓動按鈕,過程開始。然而,董事會需要相當長的時間進行編程,用戶可能會認爲該程序已經崩潰。我想要一個文本塊來顯示'Board Programming ...',以便他們知道它正在工作。
但是,目前代碼不顯示文本,直到它已經被編程,我不。知道爲什麼以下是我在點擊啓動按鈕事件代碼:
ProcessStartInfo start = new ProcessStartInfo(); //new process start info
start.FileName = STPath; //set file name
start.Arguments = "-C -ME -p " + firmwareLocation + " -v -Run"; //set arguments
start.UseShellExecute = false; //set shell execute (need this to redirect output)
start.RedirectStandardOutput = true; //redirect output
start.RedirectStandardInput = true; //redirect input
start.WindowStyle = ProcessWindowStyle.Hidden; //hide window
start.CreateNoWindow = true; //create no window
using (Process process = Process.Start(start)) //create process
{
try
{
while (process.HasExited == false) //while open
{
process.StandardInput.WriteLine(); //send enter key
programmingTextBlock.Text = "Board Programming...";
}
using (StreamReader reader = process.StandardOutput) //create stream reader
{
result = reader.ReadToEnd(); //read till end of process
File.WriteAllText("File.txt", result); //write to file
}
}
catch { } //so doesn't blow up
finally
{
int code = process.ExitCode; //get exit code
codee = code.ToString(); //set code to string
File.WriteAllText("Code.txt", codee); //save code
}
有反正去顯示進程開始運行或同時的進程正在運行之前的文本
感謝 ?露西
要操作的用戶界面和做其他事情的時候,您需要使用另一個thred。 – Whencesoever
我該怎麼做呢? – lucycopp