在C#中,该过程立即退出

问题描述 投票:-3回答:1

我有3个代码(程序)。这些是p1,p2,p3。 p1和p2是子程序。 p3是调用它们的主程序。我发布了p1.exe和p2.exe。然后在p3代码中,我使用Process()运行p1.exe和p2.exe。它可以工作,但是我将代码移到了另一台计算机上,但它不工作。在p3代码中,我使用Process()作为相同方法运行p1.exe和p2.exe。 p1.exe有效,p2.exe独立起作用,但是在p3代码中,p1.exe和p2.exe立即关闭,然后p3代码继续到下一个代码。可能是什么问题?我尝试使用相同的Visual Studio,相同的操作系统。 p1和p2代码具有IBM Cplex库,已连接有关Cplex的dll文件。是Cplex的问题吗?

p1->运行cplex模型的程序。

p2->运行另一个cplex模型的程序。

p1.exe独立工作。大约需要5分钟。

p2.exe独立工作。大约需要5分钟。

p3(主程序)->调用p1.exe和p2.exe,但其中的cplex无法正常工作。代码示例:

Process firstProc = new Process();
firstProc.StartInfo.FileName = this.t1_program; // p1.exe url
firstProc.EnableRaisingEvents = true;
firstProc.Start();
firstProc.WaitForExit();
Console.Out.WriteLine(firstProc.ExitCode);

此代码给出输出-1073741819作为退出代码。通常,此过程大约需要5分钟,但要在1秒钟内完成。通常我在Visual Studio 2017中工作。为此,在Visual Studio 2019中,我也得到了与解释相同的错误:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ILOG.OPL.opl_lang_wrapPINVOKE.OplModel_getOuterModel(IntPtr)
   at ILOG.OPL.opl_lang_wrapPINVOKE.OplModel_getOuterModel(IntPtr)
   at ILOG.OPL.OplModel.getOuterModel()
   at ILOG.OPL.OplModel.generate()
   at ILOG.OPL.OplModel.Generate()
   at T1_Cplex.Program.Main(System.String[])
-1073741819

Windows事件查看器说:

T1_Hatti.exe 
   1.0.0.0 
   5e597f86 
   coreclr.dll 
   4.700.20.11803 
   5e4c6185 
   c0000005 
   0000000000191809 
   297c 
   01d620d5ec616a74 
   C:\Users\DELL\source\repos\T1_Hatti\T1_Hatti\bin\Release\netcoreapp3.1\T1_Hatti.exe 
   C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.3\coreclr.dll 
   4572ab00-e71f-4eea-9cfc-e198ef3bc9f9 

Application: T1_Hatti.exe CoreCLR Version: 4.700.20.11803 .NET Core Version: 3.1.3 Description: The process was terminated due to an internal error in the .NET Runtime at IP 00007FFF2BD11809 (00007FFF2BB80000) with exit code c0000005. 
c# process exit cplex exit-code
1个回答
0
投票

解决了添加WorkingDirectory的问题。

© www.soinside.com 2019 - 2024. All rights reserved.