简体   繁体   English

如何在C#的单个进程中使用线程启动exe appln的多个实例?

[英]How to launch multiple instances of an exe appln using threads in a single process in c#?

在c#中,我想在一个进程中启动同一个exe应用程序的多个实例,每个实例必须在一个进程中作为不同的线程运行。

最有可能的是,您需要的是App Domains

Explaining what you're trying to achieve will help understand the problem a little better, but one approach could be: 解释您要实现的目标将有助于更好地理解该问题,但是一种方法可以是:

Code your application to check if it's already running; 对应用程序进行编码,以检查其是否已在运行; if it is, pass a message to that application telling it to create a new thread (with any parameters passed to this new instance) and then exit leaving the other process running the threads doing the work. 如果是,则向该应用程序传递一条消息,告诉它创建一个新线程(将任何参数传递给该新实例),然后退出,让其他进程运行该线程来完成工作。

Of course, if you have applications that spawn your app waiting for it to exit will require a change to the above as the application in my suggestion will exit quickly if another instance is running. 当然,如果您的应用程序产生了等待退出的应用程序,则需要对上面的内容进行更改,因为如果其他实例正在运行,我建议的应用程序将迅速退出。 You will also have to code to handle cases where the application crashes/locks up - this could block following instances of the application from telling it to run new threads. 您还必须编写代码以处理应用程序崩溃/锁定的情况-这可能阻止应用程序的后续实例告诉其运行新线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM