Asp.net mvc 3 异步进程退出,未从控制器触发c#

Asp.net mvc 3 异步进程退出,未从控制器触发c#,asp.net-mvc-3,asynchronous,delegates,system.diagnostics,Asp.net Mvc 3,Asynchronous,Delegates,System.diagnostics,我使用它从控制器的操作运行一个进程 var psi = new ProcessStartInfo(utilityPath, String.Format("{0} {1}", inputfilePath, outputfilePath)) { WorkingDirectory = Environment.CurrentDirectory, UseShellExecute = false,

我使用它从控制器的操作运行一个进程

            var psi = new ProcessStartInfo(utilityPath, String.Format("{0} {1}", inputfilePath, outputfilePath))
            {
                WorkingDirectory = Environment.CurrentDirectory,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                CreateNoWindow = true
            };

            using (var process = new Process { StartInfo = psi })
            {
                process.EnableRaisingEvents = true;
                process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
                process.ErrorDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
                process.Exited += new EventHandler(process_Exited);

                // start the process and start reading the standard and error outputs
                process.Start();

                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
                //process.WaitForExit(); //If this is commented out the delegate process_Exited never fires
            }
如果我不使用
process.WaitForExit()
由于某种原因,委托在此处注册
process.Exited+=neweventhandler(process\u Exited)永不开火


我做错了什么?

处理程序
进程\u退出
从不激发,因为
进程
变量和控制器在进程结束前被垃圾收集。如果取消注释
process.WaitForExit()
,则当前线程将被阻止,直到进程结束,并且控制器和
process
变量将不会被识别为垃圾,也不会被收集