2015-07-10 28 views
1

我有一段時間需要與ftp服務器進行通信,並將其託管在雲中。要在託管服務器中運行計劃任務,我該怎麼辦?如果有人能指點我一個有用的在線資源,那將是非常棒的。在託管服務器中定期安排一項任務c#

在此先感謝..

+0

你可以用'Timer',你不能嗎? –

+0

是的,我不確定,我是否應該創建一個定期運行的Web服務?在雲中託管服務後,它將自動運行,無需任何用戶交互。 –

+0

在您的雲計算機中,沒有任務計劃程序或支持cron作業命令? – HarryQuake

回答

1

大多數雲環境都有某種調度程序。例如Azure。 也可以在Scott Hanselmans的文章here中找到相當不錯的調度庫列表。

1

我用石英,它是真棒和直接前進。

使用的一個簡單的例子是這樣的:

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 
     } 
    } 

你可以找到石英文檔在這裏:http://quartz-scheduler.org/generated/2.2.1/html/qs-all/