在托管服务器c#中定期调度任务
本文关键字:调度 任务 服务器 | 更新日期: 2023-09-27 18:02:15
我需要在一定的时间间隔后与ftp服务器通信,并将其托管在云上。要在托管服务器中运行计划任务,我应该怎么做?如果有人能给我指出一个有用的在线资源,那就太好了。
Thanks in Advance.
我使用了Quartz,它非常棒且直接。
用法的一个简单例子是:
using Quartz;
private ScheduleCopyTask()
{
Quartz.IScheduler sched;
IJobDetail job;
ITrigger trigger;
// Instantiate the Quartz.NET scheduler
var schedulerFactory = new Quartz.Impl.StdSchedulerFactory();
sched = schedulerFactory.GetScheduler();
sched.Start();
// Instantiate the JobDetail object passing in the type of your
// custom job class. Your class merely needs to implement a simple
// interface with a single method called "Execute".
job = JobBuilder.Create<SyncJob>()
.WithIdentity("SyncJob", "group1").Build();
// Trigger the job to run now, and then every 30 mins
trigger = TriggerBuilder.Create()
.WithIdentity("SyncTrigger", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(30)
.RepeatForever()).Build();
sched.ScheduleJob(job, trigger);
}
和你的工作类别:
class SyncJob : IJob
{
public void Execute(IJobExecutionContext context)
{
// your task goes here
}
}
你可以在这里找到Quartz文档:http://quartz-scheduler.org/generated/2.2.1/html/qs-all/
大多数云环境都有某种调度器。例如Azure。此外,还可以在Scott Hanselmans的文章中找到一些非常好的调度库。
我使用http://hangfire.io/,它功能强大,但使用起来非常简单。
你也可以使用http://www.quartz-scheduler.net/,但是我没有用过,所以我不能评论它