我正在尝试使用Hangfire更新缓存中的某些列表(HttpContext.Current.Cache
)。我得到一个NullReferenceException
,因为当Hangfire呼叫它时HttpContext
为null
。
有没有办法使用Hangfire,或者我可能会寻找另一个框架?
答案 0 :(得分:0)
您无法在Hangfire中执行HttpContext
HttpContext
,因为Hangfire可以在不同的服务器和计算机上运行作业。如果您想访问更改的上下文,例如const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
;(async () => {
if ($('#mm').html() !== mm) {
hideElem('.score')
await wait(outSpeed)
hideElem('.player')
await wait(outSpeed)
hideElem('.match')
await wait(outSpeed)
updateElems()
await wait(outSpeed)
showElem('.match')
await wait(inSpeed)
showElem('.player')
await wait(inSpeed)
showElem('.score')
} else if ($('#pp').html() !== pp) {
hideElem('.score')
await wait(outSpeed)
hideElem('.player')
await wait(outSpeed)
updateElems()
await wait(outSpeed)
showElem('.player')
await wait(inSpeed)
showElem('.score')
} else if ($('#ss').html() !== ss) {
hideElem('.score')
await wait(outSpeed)
updateElems()
await wait(outSpeed)
showElem('.score')
}
})()
,您可能需要至少共享存储才能执行此操作,而changing context已针对此方案提出建议但直到现在才发生。