如何在后台执行C#控制台应用程序 [英] How to execute a C# console application in the background

查看:642
本文介绍了如何在后台执行C#控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我这个项目的目标是创建一个控制台应用程序来改变注册表中的IE设置并启动IE9。我是在vbscript上做的,想在C#上做。



问题:

我可以在后台运行该控制台App整个可执行文件有100%发布版本?我的经理不喜欢DOS后台窗口。 :(



感谢您的帮助,

Hello,
My goal of this project is to create a Console Application that changes IE settings in the registry and launches IE9. I did it on vbscript and want to do it on C#.

Question:
Can i run that console App in the background once the whole executable has the 100% release version ? My manager does not like the DOS background window. :(

Thanks for your help,

推荐答案

问题没有正确制定,因为你是困惑于控制台应用程序的概念,以及许多其他开发人员所做的。这不是你的错;这是因为Microsoft文档对此不够清楚。



所以,实际上你只需要控制台应用程序没有显示控制台之类的东西。这就是这个意思:你可以选择两种应用程序类型:控制台应用程序和Windows应用程序 这是误导性的。实际上,它意味着任何东西,Windows应用程序或控制台应用程序,默认控制台显示和任何东西,控制台隐藏。



换句话说,这两个选项都允许您在应用程序中使用Windows UI,只有第一个选项允许使用控制台,另一个选项将隐藏控制台。您可以使用所有组合。在您的情况下,您几乎从控制台开始应用程序,但将应用程序类型更改为窗口应用程序,但不添加任何窗口或窗体。在这种情况下,控制台不会显示。您甚至可以通过 System.Console 使用所有控制台输出方法,它只会无处可去,但没有例外,没有任何问题。



问题解决了。



-SA
The problem is not correctly formulated, because you are confused about the notion of "console application", and many other developers do. This is not your fault; this is because Microsoft documentation is not clear enough about it.

So, in fact you simply want something like "console application not showing console". Here is what is meant by this: you have a choice between the two application types: "Console application" and "Windows application". This is misleading. In reality, it means "Anything, windows application or console application, with default console shown" and "anything, with console hidden".

In other words, both options will allow you to use Windows UI in your application, only first options allows to also use console, another will hide console. You can use all combinations. In you cases, you practically start with console application, but change the application type to "Window application", but don''t add any windows or forms. In this case, the console won''t be shown. You can even use all your console output method via System.Console, it will just go nowhere, but no exceptions will be thrown, no problems at all.

Problem solved.

—SA


您有什么理由想要控制台吗?

这是否需要用户界面?

如果没有,只需将其设为Windows窗体应用程序,然后删除该窗体即可。打开program.cs文件,并替换Main方法中的代码。

Presto!根本没有UI。
Is there any reason why you want a console at all?
Does this need a user interface at all?
If not, just make it a windows forms app, and remove the form. Open the "program.cs" file, and replace the code in the Main method.
Presto! No UI at all.


这篇关于如何在后台执行C#控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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