简体   繁体   English

在进程之间传递命令行参数的最佳方法

[英]Best way to pass command line arguments between processes

I developed ac# single instance application. 我开发了ac#单实例应用程序。 I want to pass the command line arguments of the second instance to the already running instance before the second instance kills itself. 我想在第二个实例杀死自己之前,将第二个实例的命令行参数传递给已经运行的实例。 Is there any simple way to do this ? 有没有简单的方法可以做到这一点?

There's so many ways to do this, IMHO. 恕我直言,有很多方法可以做到这一点。

A quick and dirty way would be to anonymous pipes. 一种快速而肮脏的方法是使用匿名管道。 Just before you quit the second instance, you could make a call over the pipes, passing the command line args (maybe do a string.Join(new []{','}, args) to concatenate them first). 在您退出第二个实例之前,您可以通过管道进行调用,并传递命令行args(也许是一个string.Join(new []{','}, args)首先连接它们)。

There's so many other ways to do inter-process communications though. 但是,还有许多其他方法可以进行进程间通信。

A very simplistic example of anonymous pipes usage is give on MSDN: https://msdn.microsoft.com/en-us/library/bb546102(v=vs.110).aspx 在MSDN上给出了一个非常简单的匿名管道用法示例: https : //msdn.microsoft.com/en-us/library/bb546102(v= vs.110) .aspx

HTH. HTH。

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

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