关闭app后的C#持久化进程 [英] C# persistent process after closing app

查看:90
本文介绍了关闭app后的C#持久化进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在建立一个ac#应用程序进行一些操作并启动一个或多个外部应用程序

with



Hi,
I'm bulding a c# application who make some operation and start one or more external application
with

string pathMyApp = ......external executable
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "pathMyApp", Arguments = ......someAppParameter, };
proc = new Process() { StartInfo = startInfo, };
proc.Start()





一切都好,但在外部流程启动后,主应用程序继续结束并完成所有流程也都结束了。



是否可以关闭我的mainApp并继续执行子应用程序?





现在我已经在主应用程序结束时推出了一个读取密钥以防止结束但是它不好。

有什么解决方案吗?

谢谢



我的尝试:





It's all Ok but after external process start the main app continue to end and when it finish all process ends too.

Is it possible to close my mainApp and continue executing of child app?


Now i've putted a readkey at the end of main application to prevent the end but it's not good.
have any solution?
thank's

What I have tried:

I've tried with
<pre lang="C#">ThreadStart ths = new ThreadStart(() =&gt; proc.Start());
           Thread th = new Thread(ths);
           th.Start();</pre>

too, but is the same.

推荐答案

进程和线程在一个不同重要的尊重:当你的应用程序关闭时,如果它们被标记为后台,它的所有线程都会被关闭 - 如果它们没有,那么即使应用程序本身关闭它们也会持续存在。覆盖它的唯一方法是调用Environment.Exit而不是Application.Exit,因为它终止与应用程序关联的所有正在运行的线程,而不管它们的后台状态如何。

流程始终存在于应用程序中 - 它们与应用程序无关,并且不会自动终止。



我怀疑你需要查看你的代码再次,因为我不;认为它按照你认为的方式运作!
Processes and Threads are different in one important respect: when your application closes, all it's thread are closed as well provided they are marked as "background" - if they aren't, then they persist even once the app itself is closed. The only way to override that is to call Environment.Exit instead of Application.Exit, as that terminates all running threads associated with the app regardless of their background status.
Processes always survive the application - they are independant of the app and are not terminated automatically.

I suspect you need to look at your code again, as I dont; think it operates teh way you think it is!


这篇关于关闭app后的C#持久化进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆