我有一个字符串数组,用于将输出与另一个进程分开。然后,我希望在我的WPF接口中的textbox中显示该数组的第一个元素。但是,当我尝试这样做的时候,我收到了这个异常,有什么想法来解决它吗?
output = p.StandardOutput.ReadToEnd();
code = p.ExitCode;
p.WaitForExit();
string[] result = this.output.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
this.outputList.Add(Convert.ToDouble(result[0]));
this.MyTextBox.Text = result[0];发布于 2020-06-22 16:11:32
InvalidOperationException应该确切地告诉您是哪一行代码导致了异常。在代码周围放置一个try/catch,然后读取StackTrace属性以获得导致问题的代码行。
try
{
output = p.StandardOutput.ReadToEnd();
code = p.ExitCode;
p.WaitForExit();
string[] result = this.output.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
// If you are updating UI controls, make sure you are doing it only on the UI thread. The 'Dispatcher' will make sure the code inside is run on the UI thread.
this.Dispatcher.Invoke(() =>
{
this.outputList.Add(Convert.ToDouble(result[0]));
this.MyTextBox.Text = result[0];
});
}
catch (InvalidOperationException ex)
{
// You don't need this line, you can just put a breakpoint here to debug the problem by reading the properties of the 'ex' variable.
this.MyTextBox.Text = $"{ex.Message}\n{ex.StackTrace}";
}https://stackoverflow.com/questions/62518381
复制相似问题