我在转换为控制台应用程序的C#2008 Windows应用程序中有以下声明: 最后 { 到Console.ReadLine(); Environment.Exit(1); } 显示的错误消息表示没有足够的io内存。
以下是对正在发生的事情的更多解释: 执行的程序由从控制台应用程序转换的C#2010 Windows应用程序(称为app1)调用。 以下是从app1到C#2008应用程序的一些调用的示例,该应用程序存在名为app2的内存问题。
string[] SubPkgIDs = rData.details.Where(c => c.Package_ID.StartsWith("SUB").Select(c => c.PackID).Distinct().ToArray();
foreach (string SubPkgID in SubPkgIDs)
{
{
Process eProcess = new Process();
String Process_Arguments = null;
eProcess.StartInfo.UseShellExecute = false;
e_Process.StartInfo.FileName = "app2.exe";
Process_Arguments = " 3 " + SubPkgID;
eProcess.StartInfo.Arguments = Process_Arguments;
eProcess.Start();
eProcess.WaitForExit(1800);
//eProcess.WaitForExit();
eProcess.Dispose();
Process_Arguments = null;
}
}
I think the line of code that is causing the memory problem possibly is the following:
eProcess.WaitForExit(1800);
App1 is not waiting for a response basically from app2.exe program that is being called. It waits the 1800 *.secs and makes
the next calls. There is no reason for app1 to wait or app2 to finish executing since it does not need a response from app2.
但是如果这导致内存问题,我可以等待app2程序完成执行。
App1 and app2 were setup to be single threaded.
In the app1 program that calls the second program called app2, I am thinking of putting the following code at the end of the program:
foreach (Process proc in Process.GetProcessesByName("app2"))
{
proc.Kill();
}
这样可以释放仍在内存中的app2进程。
因此,基于我之前提到的以及我刚才提到的内容,您能告诉我代码和/或告诉我您将如何解决我遇到的内存问题吗?