Console app scheduled task run two different ways

*爱你&永不变心* 提交于 2019-12-11 23:28:39

问题


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

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.

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.

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?


回答1:


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:




回答2:


Write to flat file your param result from the first process, or database and get it from there with the second process.. Or just have your process always running and use stopwatch to perform events every 30 minutes instead of using the task scheduler, then you can keep it in memory. You have a lot of options.



来源:https://stackoverflow.com/questions/20007381/console-app-scheduled-task-run-two-different-ways

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!