How to implement Quartz.net Scheduler for simple HelloWorld

别等时光非礼了梦想. 提交于 2019-12-25 06:06:18

问题


The following code produces the following error:

Imports Quartz
Imports Quartz.Impl

Public Class InsertRssFeedJob
    Implements IJob

    Public Sub Execute(context As JobExecutionContext)
        Dim rssContoller = New RssController()
        rssController.InsertRssFeedItem("")
    End Sub

End Class

Error 1 Class 'InsertRssFeedJob' must implement 'Sub Execute(context As IJobExecutionContext)' for interface 'Quartz.IJob'. C:\Users\darchual\documents\visual studio 2010\Projects\MyBlog\MyBlog\QuartzScheduler\Class1.vb 5 16 MyBlog

I have added the library package reference and can import Quartz successfully, but "Implements IJob" has a blue line underneath of it and displays the error above. What can I do? Thank you.


回答1:


This is How I use it (first create scheduleFactory, in a different class/Sub)...

Dim schedFact As ISchedulerFactory = New StdSchedulerFactory()

' get a scheduler
Dim sched As IScheduler = schedFact.GetScheduler()
sched.Start()

' construct job info
Dim jobDetail As New JobDetail(TriggerName, Nothing, GetType(cls_schedule))
Dim trigger As Trigger = TriggerUtils.MakeDailyTrigger(hour, min)

trigger.StartTimeUtc = DateTime.UtcNow
trigger.Name = TriggerName
sched.ScheduleJob(jobDetail, trigger)

I passed the class name "cls_schedule" to JobDetail, Then you can use your class (which was passed as parameter) to Excute the actuall task.

Public Class cls_schedule
    Implements IJob

    Public Sub Execute(ByVal context As Quartz.JobExecutionContext) Implements Quartz.IJob.Execute
        Dim jobType As String = context.Trigger.Name
                 ' Your Code Goes here
    End sub



回答2:


it is the signature on the execute method, change it to IJobContext, that should solve it.



来源:https://stackoverflow.com/questions/12303637/how-to-implement-quartz-net-scheduler-for-simple-helloworld

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