可以在后台运行并与用户命令行输入交互的C#应用​​程序 [英] c# application that can run in background and interact with user command line input

查看:220
本文介绍了可以在后台运行并与用户命令行输入交互的C#应用​​程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个C#程序"A",该程序可以完成以下操作.

1.从命令窗口开始
c:\ A.exe

2.然后,"A"转到bacjground,隐藏起来.用户现在可以在相同"命令窗口中执行其他不相关的操作.
c:\ dir
c:\ notepad.exe
...

3.输入以要求"A"在背景中进行操作.
c:\ A做某事"

4.输入以退出"A"
C:\ A退出"

编写这种"A"的最简单方法是什么?控制台应用程序? Windows应用程序?多线程? Windows服务?

I''d like to write a C# program "A" which can do somthing like below.

1.Start from command window
c:\A.exe

2.Then "A" goes to bacjground, hidden. User can now do other unrelated things in the SAME command window.
c:\dir
c:\notepad.exe
...

3.Input to ask "A" to do somthing in the backgroud.
c:\A "do something"

4. Input to exit "A"
C:\A "exit"

What''s the easiest way to write such kind of "A"? console app? windows app? multithreading? windows service?

推荐答案

有趣的是,今天在C#论坛中,另一个(?)发布者也存在类似的问题.

我建议Forms应用程序是最好的选择,因为您可以从命令行启动它,而此时它作为一个独立的窗口运行.然后,您可以在应用程序继续进行所需操作时自由输入其他命令,启动新程序等.当您想与表单进行交互以执行进一步的操作或终止表单时,只需将其置于前台并根据需要进行即可.请注意,从命令行将更多命令传递给正在运行的应用程序将需要一些额外的功能,并且需要跨应用程序交互.在表单中添加一些按钮以提供所需的交互可能会更容易.
Interestingly there is a similar question in the C# forum today from another (?) poster.

I would suggest a Forms application is the best option as you can start it from the command line at which time it runs as an independent window. You are then free to enter further commands, start new programs etc while you application proceeds with whatever it needs to do. When you want to interact with your form to perform further actions or terminate it, then just bring it to the foreground and proceed as you require. Note that passing further commands to your running app from the command line will require some extra functionality and cross application interaction. It\''s probably easier to add some buttons to your form to provide the interaction you require.


这篇关于可以在后台运行并与用户命令行输入交互的C#应用​​程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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