如何在后台运行.NET控制台应用程序 [英] How to run a .NET console application in the background

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

问题描述

我有一个用C#编写的控制台应用程序,计划使用内置的Windows Task Scheduler每15分钟运行一次。

I have a console application written in C# that is scheduled to run every 15 minutes or so using the built-in Windows Task Scheduler.

每次运行时,在执行期间,黑色控制台框会弹出,然后关闭。我没有在控制台上写任何东西。

Every time it runs, the black console box pops up for the duration of its execution and then closes. I am not writing anything to the console. Is there a way to make this run in the background?

推荐答案

容易!

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

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!

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

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