从 shell 命令触发控制台应用程序中的函数调用
我将如何修改我的 c# 控制台应用程序以检索值或让 shell 命令触发方法或事件。
基本上,在应用程序加载后,我希望能够执行应用程序中的函数以及将数据传递给这些函数。
有什么方向吗?
How would I go about modifying my c# console application to retrieve values or have methods or events triggered by a shell command.
Basically after the applications loads I want the ability to be able to execute functions in the application as well as pass data to those functions.
Any Direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.NET 3.5 添加命名管道支持,我认为它可以是一个解决方案。
.NET 3.5 Adds Named Pipes Support, I think it can be a solution.
编辑:更好的链接。
您可以使用 SingleInstance 模式 - C#:如何 - single接受新参数的实例应用程序? 。
EDIT: better link.
You may use SingleInstance pattern - C# : how to - single instance application that accepts new parameters? .
您应该使用类似以下方式接受来自控制台的输入:
它将起作用,然后用户键入命令并单击 Enter,您将解析该命令并执行您需要执行的操作。
它有点像 DOS 程序一样老式,请记住,根据您的设计,您正在编写的控制台应用程序将挂起,直到用户输入值并按 ENTER 键,这意味着无法执行任何其他操作,因为调用 Console.ReadLine 的线程正在等待该命令来自用户。
you should accept input from the console using something like:
it would work, then the user types a command and clicks enter and you parse the command and execute the actions you need to execute.
it's a bit old fashion like DOS programs, and keep in mind that depending on your design the Console application you are writing would hang until the user enters value and presses ENTER key, means cannot execute anything else because the thread which callls Console.ReadLine waits that command to come from the user.