且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在后台运行.NET控制台应用程序

更新时间:2022-02-08 23:02:23

容易!

似乎难以置信,但它具有魅力。当您要执行没有任何迹象的自定义任务时,我已将其用于某些安装项目。

It seems hard to believe, but it works as a charm. I have used this for some setup projects, when you want to perform custom tasks with no signs of it.


  • 将项目创建为Windows应用程序项目(这是最困难的部分)。

  • 永远不要调用任何形式。只需保持与控制台应用程序完全一样

  • Create the project as a Windows application project (this is the hard part).
  • Never make calls to any form. Just keep on in exactly as in your console application

class Program
{
    static void Main(string[] args)
    {
        // Just don't call Application.Run(new frmMain(args));

        // ... your code
    }
 }


这是因为Windows应用程序项目与控制台并没有真正的不同,除了第一种形式和引用之外。
这是完全隐藏的执行。试试吧!

This is because windows application projects are no really different than console, except because of the first form and references. It is totally hidden execution. Try it!