控制台应用程序计划任务以两种不同方式运行 [英] Console app scheduled task run two different ways

查看:61
本文介绍了控制台应用程序计划任务以两种不同方式运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对客户端的程序,该程序需要通过计划的任务每30分钟运行一组代码。

I have a program for a client that needs to run one set of code every 30 minutes via a scheduled task.

在凌晨1:30,它需要运行单独的代码集。

at 1:30 am it needs to run a separate set of code.

这两组代码都将生成文件并将其放置在目录中。

Both sets of code will generate a file and place it in a directory.

如何设置它以能够运行两套SQL代码?

How do I set it up to be able to run two sets of SQL code?

我可以获取当前日期时间并进行比较,但这似乎笨拙。我。

I could do it getting the current date time and comparing it but that seems bulky to me.

调度任务是否可以运行一种程序,该程序会将某些内容传递给我的Main(string [] args)?

Is there a way a schedule task can run a program which would pass in something to my Main(string[] args)?

是否有正确的方法而不创建两个单独的应用程序?

Is there a correct way to do it without creating two separate apps?

推荐答案

制作程序接受参数,然后使用不同的参数来调度您的控制台应用程序(使用Windows计划程序)……

Make your program accept parameters, then schedule your console app (using Windows scheduler) with the different parameters... something like:

void Main(string[] args)
{
    var firstArg = args.FirstOrDefault();
    if (firstArg == "option1")
    {
        // do stuff
    }
    else if (firstArg == "option2")
    {
        // do other stuff
    }
}

在调度程序中做类似的事情:

In scheduler do something like:

这篇关于控制台应用程序计划任务以两种不同方式运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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