如何在运行时将命令行参数传递给C#Windows Forms应用程序 [英] How to pass a command line argument to a C# windows forms application while it is running

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

问题描述

我有ac#Windows窗体应用程序框架2.0

I have a c# windows forms application framework 2.0

我希望能够将另一个进程或命令行中的命令传递给我的Windows窗体应用程序应用程序正在运行。我如何发送和如何接收?

I want to be able to pass a command from another process or from command line to my windows forms application while my application is running. How can I send and how can I receive?

我知道可以通过IPC来完成,但是我现在还不想去那儿,因为通过传递参数功能会

I know it can be done thought IPC but I dont want to go there just yet as this passing the argument feature will be rarely used and I am trying make minimal changes in the windows forms application as possible.

编辑:现在,我通过双击图标来运行Windows窗体应用程序。我将其作为进程从命令行运行(控制台应用程序??)并从命令行发送命令?

edit: Right now the I run windows forms application by double-clicking icon..Can I make it run from command line as a process (console application???) and send commands from command-line?

编辑:进一步说明:该命令由用户。

Further clarification: The command is entered by user.

推荐答案

您不能将参数传递给已经运行的程序。

You can't pass arguments to an already-running program.

您已经提到,执行此操作的标准方法是启动一个新实例来接收参数,检测已运行的实例,然后通过IPC发送命令。

The standard method for doing this, as you mentioned, is starting a new instance to receive the arguments, detecting the already-running instance, and sending it commands via IPC.

如其他一些答案的注释中所述,有可能使应用程序不断从命令行。这称为标准输入流,并且可以在.NET中通过此处中记录的Process.StandardInput类。同样,应用程序也具有标准输出和标准错误流。

As mentioned in the comments for some of the other answers, it is possible to have an application continually reading data from the command line. This is called the Standard Input stream, and is available in .NET via the Process.StandardInput class, documented here. Likewise, applications also have standard output and standard error streams.

可以从其他应用程序中利用标准输入,但最终归结为实施IPC形式。

Standard input can be leveraged from other applications, but ultimately that comes down to implementing a form of IPC.

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

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