I need to execute my console app for many files in a loop and update my GUI. When I execute my app for the first time everything is ok, GUI updates are done in realtime. But with every iteration, reading of console output get longer delay. After 3-4 files I get only few updates or no updates at all. Its not a problem with updating GUI, my dataraceivedevent doesn't fire up.
I can't understand why, because after every iteration I close and dispose my process.
This is the method that I execute in the for-loop.
public void execute(string arguments, string path)
{
Process myProcess = new Process();
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.FileName = path;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.Arguments = arguments;
myProcess.Start();
myProcess.BeginOutputReadLine();
myProcess.OutputDataReceived += new DataReceivedEventHandler(this.updateProgress);
myProcess.WaitForExit();
myProcess.CancelOutputRead();
myProcess.OutputDataReceived -= updateProgress;
myProcess.Close();
myProcess.Dispose();
if (progressBar1.InvokeRequired)
{
progressBar1.BeginInvoke(new Action(() =>
{
progressBar1.PerformStep();
}));
}
else
{
progressBar1.PerformStep();
}
if (progressBar2.InvokeRequired)
{
progressBar2.BeginInvoke(new Action(() =>
{
progressBar2.Value = 100;
progressBar2.Refresh();
}));
}
else
{
progressBar2.Value = 100;
progressBar2.Refresh();
}
if (this.InvokeRequired)
{
this.BeginInvoke(new Action(() =>
{
this.Text = " ";
}));
}
else
{
this.Text = " ";
}
Thread.Sleep(500);
}