第二次运行进程时出现问题,内存使用量增加c#

第二次运行进程时出现问题,内存使用量增加c#,c#,memory,process,C#,Memory,Process,我的问题是,第一个进程在不到一秒钟的时间内以最大值执行,将消耗大约20MB的内存,并将恢复正常,但每次在此之后重新启动该进程,即使是一个小时后,也将花费大约1分钟的时间来完成该工作,并将占用超过1200MB的内存,此后不会下降。 唯一的解决方法是在每次使用后重新启动应用程序 using (var compiler = new Process { StartInfo =

我的问题是,第一个进程在不到一秒钟的时间内以最大值执行,将消耗大约20MB的内存,并将恢复正常,但每次在此之后重新启动该进程,即使是一个小时后,也将花费大约1分钟的时间来完成该工作,并将占用超过1200MB的内存,此后不会下降。 唯一的解决方法是在每次使用后重新启动应用程序

using (var compiler = new Process
                        {
                            StartInfo =
                            {
                                FileName = _installPath + @"\Papyrus Compiler\PapyrusCompiler.exe",
                                Arguments = $@"{(string) tab.Tag} -f=""TESV_Papyrus_Flags.flg"" -i=""{_installPath}\Data\scripts\source"" -o=""{_installPath}\Data\scripts""",
                                UseShellExecute = false,
                                RedirectStandardOutput = true,
                                RedirectStandardError = true,
                                CreateNoWindow = true
                            }
                        })
                        {
                            compiler.Start();

                            Console.WriteLine(compiler.StandardError.ReadToEnd());
                            Console.WriteLine(compiler.StandardOutput.ReadToEnd());

                            compiler.WaitForExit();
                        }
提前谢谢你的帮助

编辑: 做了一些改变,但毫无帮助

using (var compiler = new Process
                    {
                        StartInfo =
                        {
                            FileName = _installPath + @"\Papyrus Compiler\PapyrusCompiler.exe",
                            Arguments = $@"{tab.Tag as string} -f=""TESV_Papyrus_Flags.flg"" -i=""{_installPath}\Data\scripts\source"" -o=""{_installPath}\Data\scripts""",
                            UseShellExecute = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError = true,
                            CreateNoWindow = true
                        }
                    })
                    {
                        string eOut = null;
                        compiler.ErrorDataReceived += (sender, e) =>
                        {
                            eOut += e.Data;
                        };

                        compiler.Start();

                        compiler.BeginErrorReadLine();
                        var ou = compiler.StandardOutput.ReadToEnd();

                        compiler.WaitForExit();

                        Console.WriteLine(eOut);
                        Console.WriteLine(ou);
                    }
还有一件事我在第一次将控制台重定向到文本框时没有提到

        readonly TextWriter _writer;

    public Form1(string args)
    {
        InitializeComponent();

        // Instantiate the writer
        _writer = new TextBoxStreamWriter(output);
        // Redirect the out Console stream
        Console.SetOut(_writer);
    }

经过这么长时间的吹毛求疵,我决定尝试其他方法来解决这个问题。 我用这个方法创建了一个新的应用程序,只需点击一个按钮,测试它是否会在第二次编译脚本时挂起。令我惊讶的是,问题没有了

然后,我决定尝试通过从原始应用程序中添加更多操作来重现我的错误。当我添加输出时。Clear();发现问题后,它开始挂起

我还尝试了输出。Text=“”;但它仍将开始悬挂