似乎无法使Quartz .Net在VB.Net Web应用程序项目上运行

时间:2011-05-29 02:44:47

标签: asp.net vb.net quartz.net

我按照Quartz手册进行了操作,但我仍然不确定为什么它没有在 Global.asax 中获取GetDeal.vb(Quartz作业)。它从未进入 _scheduler.JobGroupNames  和 _scheduler.TriggerGroupNames 循环如下:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

    Dim factory As ISchedulerFactory = New StdSchedulerFactory()
    _scheduler = factory.GetScheduler()
    _scheduler.Start()

    If _scheduler.IsStarted Then
        Dim jobs As String = ""
        Dim jobGroup As String = ""
        For Each jobGroup In _scheduler.JobGroupNames
            Dim jobName As String
            For Each jobName In _scheduler.GetJobNames(jobGroup)
                jobs = jobs + " " + jobName
            Next
        Next

        jobs = ""
        For Each jobGroup In _scheduler.TriggerGroupNames
            Dim jobName As String
            For Each jobName In _scheduler.GetTriggerNames(jobGroup)
                jobs = jobs + " " + jobName
            Next
        Next
    End If

End Sub

我附上了一个链接,可以在这里下载我的项目。有关如何使其工作的任何建议? - http://www.uniquevolve.com/YouMeCoupon.zip

1 个答案:

答案 0 :(得分:1)

以这种方式更改作业的命名空间:Namespace Jobs

这是完整的文件:

Imports Quartz

' Namespace YouMeCoupon.Jobs
Namespace Jobs

Public Class GetDeal : Implements Quartz.IJob


    Public Sub Execute(ByVal context As Quartz.JobExecutionContext) Implements Quartz.IJob.Execute
        Dim data As JobDataMap = context.MergedJobDataMap
        'Dim url As String = data.GetString("URL")

        Try
            Dim a As String
            a = "testing"

        Catch ex As Exception

        End Try

    End Sub
End Class

End Namespace

我建议您使用日志系统来调试Quartz.net。 你必须有这些参考:

Common.Logging.dll Common.Logging.NLog.dll NLog.dll

然后您可以为NLog(NLog.config)添加配置文件

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <targets>
        <target name="DebugHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${identity} ${aspnet-request}   ${message}  ${exception}" />
        <target name="ErrorHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
        <target name="FatalHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
        <target name="GenericHandler" type="File" filename="${basedir}/_Logs/${date:format=yyyyMMdd}_${level}.Log"
            layout="${longdate} ${logger}   ${aspnet-session:variable=UserName} ${threadid} ${environment}  ${aspnet-request}   ${message}  ${exception}" />
    </targets>
    <rules>
        <logger name="*" level="Debug" appendTo="DebugHandler" />
        <logger name="*" level="Error" appendTo="ErrorHandler" />
        <logger name="*" level="Fatal" appendTo="FatalHandler" />
        <logger name="*" levels="Info,Warn" appendTo="GenericHandler" />
    </rules>
</nlog>

并更改您的web.config,添加以下部分:

<sectionGroup name="common">
  <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
        <arg key="configType" value="FILE" />
        <arg key="configFile" value="~/NLog.config" />
      </factoryAdapter>
    </logging>
  </common>

现在,应该在_Logs中跟踪所有内容(您必须将其添加到项目中)。你更容易理解发生了什么 您可以使用记录here找到更新的解决方案。 还可以查看Quartz.net版本。在我看来,你没有使用最后一个:1.3。