小编Joã*_*nes的帖子

当重定向输出相对较大时,启动进程挂起

我今天遇到了这个问题,我花了很长时间才搞清楚.我从IIS中启动一个进程,重定向它的标准输出和错误输出,所以当进程退出时,我就能用它生成一个日志.我的机器上的一切运行正常,但在我发布之后不太好.

这个过程应该只运行一段时间然后退出,但事实并非如此.它只是停止响应,持有像套接字这样的资源.经过一段时间,我能够找出问题的原因:生成的日志太大了.Console.WriteLine从运行过程中评论后,一切正常.

只是为了澄清我是如何开始这个过程的:

Process process = new Process();
process.StartInfo.FileName = path;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.EnableRaisingEvents = true;
process.Exited += Process_Exited;
process.Start();
Run Code Online (Sandbox Code Playgroud)

以及我如何处理退出:

private static void Process_Exited(object sender, EventArgs e)
{
    Process process = (Process)sender;
    File.WriteAllText(path, process.StandardOutput.ReadToEnd() +
    "\r\nEXCEPTIONS\r\n" + process.StandardError.ReadToEnd());
}
Run Code Online (Sandbox Code Playgroud)

即使我已经知道如何修复它,我仍然想知道发生了什么以及为什么,因为我必须有办法创建一个我想要的大日志.

c# asp.net iis process redirectstandardoutput

6
推荐指数
1
解决办法
2107
查看次数

标签 统计

asp.net ×1

c# ×1

iis ×1

process ×1

redirectstandardoutput ×1