Haider Ali
Haider Ali

Reputation: 2795

process.waitforexit hangs

Dont mark downvote untill you dont read it fully. however many questions exists by same heading, none of them is working, and i want to solve my specific problem. Please help.

I am working on C#4.0 Asp.Net application, On a web page on button click i want to create an exe. So that i am using devenv.exe, but it hangs on process.waitforexit command.

This was working, for more then 7 monnths, but before two days suddenly it stoped working. It is also working on localhost, after publishing on server it is not working. The code is below

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;
}

Upvotes: 0

Views: 975

Answers (2)

Haider Ali
Haider Ali

Reputation: 2795

As @Damien_The_Unbeliever said, I tried MSBuild.Exe, and it is worked well. Still now, it is not recognised why devenv.exe stoped working.

However msbuild.exe is working well.

Note: MSBuild.exe can be used through command prompt and for complie a project by coding, we can use this, command line utility.

msbuild.exe located in following locations, be care full regarding version

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

target project/solution framework version and msbuild.exe version should be same.

if someone need help about msbuild.exe this link may be too use full http://msdn.microsoft.com/en-us/library/ms164311%28v=vs.90%29.aspx It Contains whole command line arguments documentation

Thanx @Damien_The_Unbeliever for your hint.

Upvotes: 1

Bedouin
Bedouin

Reputation: 490

If it was working 2 days ago, and you didn't change any thing to your code, so look arround permissions, may be someone for some reasons changes the permissions on the server.

Other ways, if some changes occured on the code of (the asp.net application or on the .exe), start by going a step back (cancel last changes), and try again if it works, and if so, then look deeply in your changes, the problem is somewhere there.

Becarefull about the timeout of your process, it should not exceed the http request timeout (set by default to 20 sec).

Upvotes: 0

Related Questions