NullReferenceException while handling ErrirDataReceived - killed thread
im trying to make c# application that acts as java application wrapper -
one of functions im trying to implement is to redirect console output to
my program, unfortunally, when i kill my java process, the whole program
freezes. there is code:
private void button1_Click(object sender, EventArgs e)
{
String start = @"myjavaapp.jar";
var startInfo = new ProcessStartInfo("java", start);
startInfo.RedirectStandardInput = startInfo.RedirectStandardError
= true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process ServerProc = new Process();
ServerProc.StartInfo = startInfo;
ServerProc.EnableRaisingEvents = true;
ServerProc.ErrorDataReceived += new
DataReceivedEventHandler(ServerProc_ErrorDataReceived);
ServerProc.Exited += new EventHandler(ServerProc_Exited);
ServerProc.Start();
ServerProc.BeginErrorReadLine();
}
private void ServerProc_ErrorDataReceived(object sender,
DataReceivedEventArgs e)
{
Invoke(new Action(() =>
{
if (e.Data.Contains("nastything"))
{
System.Windows.Forms.MessageBox.Show("Something nasty
happened in console ");
}
f2.richTextBox1.AppendText(e.Data + "\n");
}));
I think there is something wrong with my thread managing - maybe i dont
understand it yet. anyway, in debug mode vs2012 returns me
nullreferenceexception.
No comments:
Post a Comment