Eu tenho uma matriz de string que uso para dividir a saída de outro processo. Em seguida, quero exibir o primeiro elemento dessa matriz em uma caixa de texto na minha interface WPF. No entanto, recebo esta exceção quando tento fazer isso, alguma idéia de como consertar?
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];
O InvalidOperationException deve informar exatamente qual linha de código causou a exceção. Coloque um try / catch em seu código e, em seguida, leia a propriedade StackTrace para obter a linha de código que está causando o problema.
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}";
}
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras