如何将命令行参数传递给正在运行的exe C# [英] How to pass command line arguments to a running exe C#

查看:376
本文介绍了如何将命令行参数传递给正在运行的exe C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个C#程序,从启动运行....我想做的是......



1.将其设为单个实例应用程序...

2.当用户双击桌面上的某些特定文件时,应将文件名传递给我的应用程序的运行实例作为命令行参数(现在它在不同的实例中打开)



请帮助我:(

Hi all,

I have a program in C# that runs from startup.... What I want to do is...

1. Make it single Instance Application...
2. When The user will double click some specific files from desktop, The file name should be passed to the running instance of my application as Command Line arguments(Now it opens in separate instances)

Please help me :(

推荐答案

这个问题有两个部分,分别解决。首先回答第二部分,你需要能够在你的应用程序中设置某种进程间通信,以便接受请求来自另一个程序,当它已经运行。我建议使用管道(或共享内存或网络连接或dde)。如果你有一个'虚拟'第二个应用程序通过连接发送数据,它可能是最容易开发/实现的。由您正在运行的应用程序执行。首先运行此程序。



第二部分实际上是你的第一个问题。 Google将为您提供多种单实例应用程序机制。在应用程序的启动代码中,如果它检测到它是第二个(或后续)实例正在运行,请收集命令行信息并使用您在上面开发的代码将其转发到第一个实例。
There are 2 parts of this question, which are solved separately. To answer the second part first, you need to be able to set up some sort of inter-process communication in your app so that it will accept requests from another program when it is already running. I suggest use of a pipe (or shared memory or network connection or dde). It is probably easiest to develop/implement if you have a 'dummy' second app that sends data over the connection and is executed by your running app. Get this running first.

The second part is actually your first question. Google will give you numerous mechanisms for single instance apps. In the startup code for your app, if it detects that it is the second (or subsequent) instance running, collect the command line info and relay that to the first instance using the code you developed above.


在我过去的答案中,我提供了解决此问题和相关问题的方法的全面描述。请参阅:

仅向一个流程实例输入多个命令 [ ^ ],

自定义Windows右键单击命令启动多个实例 [ ^ ]。



-SA
In my past answers, I provided a comprehensive description of the approach solving this and related problem. Please see:
Enter multiple commands to only one process instance[^],
Custom Windows right-click command launching multiple instances[^].

—SA


参考这篇文章

< a href =http://stackoverflow.com/questions/653563/passing-command-line-arguments-in-c-sharp> http://stackoverflow.com/questions/653563/passing-command-line-arguments -in-c-sharp [ ^ ]


这篇关于如何将命令行参数传递给正在运行的exe C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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