Как превратить этот код в "асинхронный режим", потому что мой процесс frezze, когда я запускаю длинный процесс standardoutput перенаправления DOS-подобных программ.
Как превратить этот код в "асинхронный режим", потому что мой процесс frezze, когда я запускаю длинный процесс standardOutput перенаправления DOS-подобных программ.
public void Process_Ex(string fileName, string arguments) { My problem is here var psi = new ProcessStartInfo(fileName, arguments); // Set the options. psi.UseShellExecute = false; psi.ErrorDialog = false; psi.CreateNoWindow = true; // Specify CodePage Output var encoding = Encoding.GetEncoding(850); psi.StandardOutputEncoding = encoding; psi.StandardErrorEncoding = encoding; // Specify redirection. psi.RedirectStandardError = true; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; // Create process. var process = new Process(); process.EnableRaisingEvents = true; process.StartInfo = psi; process.Start(); string s = process.StandardOutput.ReadToEnd(); richTextBox1.Text = s; toolStripStatusLabel1.Text = "Runngig Process : " + fileName; return; }
Что я уже пробовал:
Я сори, если код, как случайно написанный.
process.BeginOutputReadLine(); process.WaitForExit(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); string otp = process_ErrorDataReceived; richTextBox1.Text = process_ErrorDataReceived; StreamReader reader = new StreamReader(); var sortOutput = new StringBuilder(""); process.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler); process.BeginOutputReadLine(); process.OutputDataReceived += p_OutputDataReceived; private void SortOutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { var sortOutput = new StringBuilder(""); sortOutput.Append(Environment.NewLine + "[" + numOutputLines.ToString() + "] - " + outLine.Data); sortOutput.Append(Environment.NewLine + "[" + "] - " + outLine.Data); richTextBox1.AppendText(sortOutput.ToString()); if (this.InvokeRequired) this.Invoke(new UpdateLabelDelegate(this.)); richTextBox1.Invoke(); void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { string RTB = (e.Data); richTextBox1.Invoke((Delegate) => richTextBox1.Text = RTB; richTextBox1.Text += RTB; Console.Write(e.Data);