当我在我的机器上调试时,httpModule 在将它发布到 IIS 后现在正常触发,它没有运行,我做错了什么?我错过了什么吗?
这是 web.config 中的样子
<httpModules>
<add type="MyApp.Web.Mvc.Modules.Scheduler" name="Scheduler" />
</httpModules>
那么调度程序看起来像这样
public class Scheduler : IHttpModule
{
private static readonly object Job;
private static Timer timer;
static Scheduler()
{
Job = new object();
}
void IHttpModule.Init(HttpApplication application)
{
try
{
if (timer == null)
{
var timerCallback = new TimerCallback(ProcessJobs);
const int startTime = 10 * 1000;
const int timerInterval = 60 * 1000; // 1 minute
timer = new Timer(timerCallback, null, startTime, timerInterval);
}
}
catch (Exception ex)
{
//exception code here
}
}
public void Dispose()
{
}
protected void ProcessJobs(object state)
{
try
{
// This protects everything inside from other threads that might be invoking this
// which is good for long running processes on the background
lock (Job)
{
//My Stuff
}
}
catch (Exception ex)
{
//exception code here
}
}
}