如何在不干扰网站的情况下从 asp.net 启动进程?
我们有一个能够创建 .air 文件的 asp.net 应用程序。 为此,我们使用以下代码:
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();
现在的问题是,有时服务器的 cpu 达到 100%,导致应用程序运行非常慢,甚至丢失会话(我们认为这就是问题所在)。
关于如何生成air文件或运行外部进程而不干扰asp.net应用程序,还有其他解决方案吗?
干杯, M。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在这里:
process.WaitForExit();
,您只是停止了应用程序的执行。您可能想要使用线程来启动进程,并使用某种 IPC(进程间通信,如远程处理、命名管道)来了解生成何时完成。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.