安排一个C#控制台应用程序 [英] Schedule a C# console application

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

问题描述

我给了一个任务来创建一个针对批量运行电子邮件C#控制台应用程序。我很新的C#区域,所以我不知道我的方向的想法。这个C#控制台应用程序将被部署在服务器上,并期望在基于服务器时间一定时间运行。

I've given a task to create an email C# console application which targeted to run as batch. I'm very new to C# area and hence I have no idea about my direction. This C# console application will be deployed on a server and expect to run in certain time based on server time.

经过一番研究,大部分的建议是有关使用任务调度程序或窗口服务,但我想知道如果这个C#控制台应用程序在某种程度上可以运行自己的自己的?也许以后执行它,那么它自己注册到服务器,服务器会定期处理呢?

After some research, most of the suggestions are about using task scheduler or window services, but I'm wondering if this C# console application is somehow possible to run own its own? Maybe after execute it, it then register itself into the server and the server will handle it periodically?

推荐答案

如果您想要管理通过代码调度看看Quartz.NET: http://quartznet.sourceforge.net/

If you want to manage the scheduler by code have a look at Quartz.NET: http://quartznet.sourceforge.net/

该库提供的就业机会和触发器的创建。

This library provides the creation of jobs and triggers.

如(直接: http://quartznet.sourceforge.net/tutorial/lesson_3.html ):

// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();

// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(DumbJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeHourlyTrigger();
// start on the next even hour
trigger.StartTime = TriggerUtils.GetEvenHourDate(DateTime.UtcNow);  
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger);

现在,这意味着你的控制台应用程序应该继续运行,这使得它真的不适合这份工作。

Now this means your console application should run continuously which makes it not really suitable for the job.

选项1.通过一个执行你的控制台应用程序的任务调度程序(真正简单的)添加一个任务。见示例任务: http://www.sevenforums.com /tutorials/12444-task-scheduler-create-new-task.html

Option 1. Add a task via task scheduler (real easy) that executes your console application. See example task: http://www.sevenforums.com/tutorials/12444-task-scheduler-create-new-task.html

选项2.创建一个Windows服务(不复杂),它使用图书馆像Quartz.NET或.NET的定时器类scheduele工作和执行批量操作。请参阅创建Windows服务的 http://msdn.microsoft.com/en-us /library/zt39148a.aspx

Option 2. Create a windows service (not to complicated) that uses a library like Quartz.NET or .NET's Timer class to scheduele jobs and executes a batch operation. See for creation of windows service http://msdn.microsoft.com/en-us/library/zt39148a.aspx

选项3.让你的控制台应用程序实现scheduele库像Quartz.NET或/ Net的的定时器类并运行它作为一种服务(稍微复杂)的创建可执行

Option 3. Make your console application implement a scheduele library like Quartz.NET or /Net's Timer class and run it as a service (a bit more complex): Create Windows service from executable

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

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