Quartz Execute中的ContextualCompositionHost(后台进程)

时间:2014-05-06 04:17:49

标签: asp.net mef quartz.net httpcontext

我有这种方法定期发送通知消息:

Public Overrides Sub Execute(context As Quartz.IJobExecutionContext)
    Try
        Logger.Write("NotificationJob execute start")
        _service = ContextualCompositionHost.Container.GetExportedValue(Of IMessageService)()
        _service.SendMessages()
        Logger.Write("NotificationJob execute end")
    Catch ex As Exception
        Logger.Write("NotificationJob error: " + ex.Message + ", " + ex.StackTrace)
    End Try
End Sub

ContextualCompositionHost.ContainerGlobal.asaxWebControls中使用时效果很好,但该对象未在上面的代码中创建,WebScope

Public Enum WebScopeMode
    Application
    Request
End Enum

ScopedContainerHttpModule中的以下方法出现错误:

Private Sub SetUpRequestLevelContainerCreation()
     ContextualCompositionHost.Initialize(Function() HttpContext.Current.Items, AddressOf CreateRequestContainer)
End Sub

HttpContext.CurrentNothing

任何人都知道为什么以及如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Quartz.Net作业在.Net线程池中运行,而不是在计划作业的线程上运行,因此在运行作业时没有http上下文。在安排作业时,您应该将作业所需的所有数据传递到作业数据图中。