c# - Starting a separate exe and exiting the current programm
问题描述
I am trying to start a second exe-program from within a c# program. This is my current code:
Process p = new Process();
p.StartInfo.FileName = System.Windows.Forms.Application.StartupPath + "\\HASy-Diag.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = "git-synchro " + args[1];
p.StartInfo.UseShellExecute = false;
p.Start();
But here is the catch: I want to exit my program right after I started the second exe.
The point is, that I have to do some asynchronous work, which cannot be in the same process as the programm. Note here, that is has to be in another process, not another thread. The reason is, that I want to do some work next to a build from an IDE. Running commands before and after the build is implemented in that IDE. The IDE (Keil here) waits, until the prebuild-process is finished (thats why I have to stop it) and then starts to build.
I want to retrieve information while the IDE builds the project (to essentially save time). So I want to start a new process from within a process.
is that possible? Any process I start with then given code above does not execute if you exit the full program. This code only executes if I have p.waitForExit()
in the code.
解决方案
Use p.WaitForExit with parameter - pass 0 miliseconds, so your app will not wait but continue normally:
p.WaitForExit(0);
This method returns true if process ended and false if it is still in progress, but in your case it will not matter.
推荐阅读
- reactjs - 数据道具从状态更改后React-Table不更新
- reactjs - React Native Component 不会随着状态变化而更新
- ios - SwiftUI Animation.fluidSpring() 替换
- javascript - JavaScript 新手需要“未定义”结果的帮助
- image - 由于错误的 EXIF 数据,JPEG 照片在插入 Adobe LiveCycle 图像字段时不会显示
- python - Scrapy登录适用于某些网站,但不适用于其他网站
- vue.js - 如何使用 vue.js 在选择中设置默认选定值?
- webpack - 使用 webpack 加载二进制文件并转换为 Blob
- postgresql - 无法终止 Postgresql DB 上的活动会话
- python - 根据另一列中的唯一值计算项目出现在熊猫数据框中的列中的次数