Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you start a process from asp.net without interfering with the website?

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.

like image 581
user29964 Avatar asked Sep 11 '25 06:09

user29964


1 Answers

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.

like image 63
Femaref Avatar answered Sep 12 '25 21:09

Femaref