【问题标题】:In C# the process exits immediately在 C# 中,进程立即退出
【发布时间】:2020-05-09 19:29:47
【问题描述】:

我有 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(main program) -> 调用 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. 

【问题讨论】:

  • 捕获标准输出/标准错误以进行诊断?这些程序必须附加到终端吗?
  • 当您在 p3 之外的命令提示符/shell 中运行这些子程序时是否发生过?也许您错过了复制程序所需的某些依赖项 (DLL)
  • @nijave 我试图从 cmd 运行子程序。他们工作了。他们有 dll 文件。
  • @user2864740 是的,它们是终端程序。
  • 设置WorkingDirectory。如果调用进程不是.Net Core,则UseShellExecute默认为trueEnableRaisingEvents = true 仅用于引发 Exited 事件。如果这些程序需要命令行参数,请使用ProcessStartInfo.Arguments 属性,不要将它们添加到可执行文件名中。

标签: c# process exit cplex exit-code


【解决方案1】:

通过添加 WorkingDirectory 解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多