Hello everyone, I am calling up FFMPEG and passing arguments to it to transcode video files. The program works great with my existing code, however when it is working on any larger files, I noticed that my program freezes while FFMPEG is running. As it runs, I read the standard error output, which give me status and progress updates about twice a second.

I know the problem is in Synchronous vs Asynchronous processes, but the sample code I have seen for Async Processes only appears to check for the output once, whereas I need to read it continuously as it comes available. I have a "kill-switch" which I want to check periodically to be able to abort the process, but once I call FFMPEG, it doesn't get read until after it has finished... There has to be a way to run asynchronous and still continuously monitor the output, right?


Code:
                        Process proc = new Process();
                        proc.StartInfo.FileName = "C:\\FFMPEG\\bin\\ffmpeg.exe";
                        proc.StartInfo.Arguments = "-i " + sourceFile + "-c:v dnxhd -b:v 185M -r 29.97 -s 1920x1080 -pix_fmt yuv422p10le -flags +ildct -c:a pcm_s24le -ar 48k dnxhdoutput.mov";
                        proc.StartInfo.RedirectStandardError = true;
                        proc.StartInfo.RedirectStandardOutput = true;
                        proc.StartInfo.CreateNoWindow = true;
                        proc.StartInfo.UseShellExecute = false;
                        proc.EnableRaisingEvents = true;

                        if (!proc.Start())
                        {
                            Console.WriteLine("Error starting");
                            return;
                        }

                        StreamReader reader = proc.StandardError;
                        string line;
                        string fileName = Path.GetFileName(Item.Text); //get the filename without path...
                        int fileNum = Item.Index + 1;
                        while ((line = reader.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                            labelStatus.Text = fileNum + " of " + fileList1.CheckedIndices.Count + ": " + fileName + " - " + line;
                            labelStatus.Update();

                            //Check for Kill Switch!
                            //if (checkKill.Checked == true)
                            //{
                            //    proc.Close();
                            //}

                        }
                        proc.Close();