views:

46

answers:

1

Hi,

We have an asp.net application that is able to create .air files. To do this we use the following code:

System.Diagnostics.Process process = new System.Diagnostics.Process();

//process.StartInfo.FileName = strBatchFile;
if (File.Exists(@"C:\Program Files\Java\jre6\bin\java.exe"))
{
    process.StartInfo.FileName = @"C:\Program Files\Java\jre6\bin\java.exe";
}
else
{
    process.StartInfo.FileName = @"C:\Program Files (x86)\Java\jre6\bin\java.exe";
}
process.StartInfo.Arguments = GetArguments();
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.PriorityClass = ProcessPriorityClass.Idle;

process.Start();

string strOutput = process.StandardOutput.ReadToEnd();
string strError = process.StandardError.ReadToEnd();

HttpContext.Current.Response.Write(strOutput + "<p>" + strError + "</p>");

process.WaitForExit();

Well the problem now is that sometimes the cpu of the server is reaching 100% causing the application to run very slow and even lose sessions (we think this is the problem).

Is there any other solution on how to generate air files or run an external process without interfering with the asp.net application?

Cheers, M.

+4  A: 

The problem is here: process.WaitForExit();, you are simply halting the execution of the application. You might want to use a thread to start the process and some sort of IPC (Inter Process Communication, like remoting, named pipes) to know when the generation is finished.

Femaref