[英]process.waitforexit hangs
不要标记下降投票,直到您没有完全阅读为止。 但是,同一标题下存在许多问题,但没有一个起作用,我想解决我的特定问题。 请帮忙。
我正在使用C#4.0 Asp.Net应用程序,在按钮上的网页上单击我要创建一个exe。 这样我就在使用devenv.exe ,但是它挂在process.waitforexit命令上。
这已经工作了七个多月,但是在两天前突然停止工作了。 它也在localhost上运行,在服务器上发布后无法正常运行。 代码如下
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\devenv.exe";
process.StartInfo.Arguments = @"D:\ProjFolder\xxx.sln /rebuild";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
OutputMsg = "";
if (!process.Start())
{
OutputMsg = "failed.</br>";
OutputMsg += process.StandardError.ReadToEnd();
HttpContext.Current.Response.Write(OutputMsg);
return false;
}
// Some people said that this is buffer problem, you should release it by reading
// output, i used "ReadToEnd" that is not working, so trying this again, and also it
// is not working
//while (!process.StandardOutput.EndOfStream)
//{
//string outputmsg = process.StandardOutput.ReadLine();
//HttpContext.Current.Response.Write(outputmsg);
//}
//string output = process.StandardOutput.ReadToEnd();
process.WaitForExit(60000);
if (process.HasExited)
{
OutputMsg = "Succeeded.";
HttpContext.Current.Response.Write(OutputMsg);
}
else
{
OutputMsg = "Process not completed properly.";
process.Kill();
HttpContext.Current.Response.Write(OutputMsg);
return false;
}
正如@Damien_The_Unbeliever所说,我尝试了MSBuild.Exe ,并且运行良好。 直到现在,仍然不知道为什么devenv.exe停止工作。
但是,msbuild.exe运行良好。
注意:可以通过命令提示符使用MSBuild.exe,并通过编码来编译项目,我们可以使用此命令行实用程序。
msbuild.exe位于以下位置,请注意版本
C:\Windows\Microsoft.Net\Framework\v2.0.50727\MSBuild.exe
C:\Windows\Microsoft.Net\Framework\v3.5\MSBuild.exe
C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe
目标项目/解决方案框架版本和msbuild.exe版本应该相同。
如果有人需要有关msbuild.exe的帮助,则此链接可能也使用完整的http://msdn.microsoft.com/zh-cn/library/ms164311%28v=vs.90%29.aspx,其中包含整个命令行参数文档
感谢@Damien_The_Unbeliever的提示。
如果它在2天前仍在运行,并且您没有对代码进行任何更改,那么请查看周围的权限,可能由于某些原因有人更改了服务器上的权限。
其他方法,如果(.asp.net应用程序或.exe)的代码发生了某些更改,请从后退一步(取消上一次更改)开始,然后再试一次是否可行,如果可以,请仔细查看在您的更改中,问题出在哪里。
请注意进程的超时,它不应超过http请求超时(默认设置为20秒)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.