我正在使用作为服务安装的 Quartz.net 2.2。作业存储在 ms sql express 中,使用 AdoJobStore。这些作业是从 asp.net 4 网站管理的。一切正常,正如预期的那样:服务正在运行,作业已正确存储和触发。我面临的问题是,每天早上 7 点之后(这是应用程序池回收的时间)并且我访问该站点时,它会给出以下错误:
对象“/QuartzScheduler”已断开连接或在服务器上不存在。
[RemotingException:对象'/QuartzScheduler'已断开连接或在服务器上不存在。] System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9443827 System.Runtime.Remoting.Proxies.RealProxy。 PrivateInvoke(MessageData& msgData, Int32 type) +345 Quartz.Simpl.IRemotableQuartzScheduler.get_SchedulerName() +0 Quartz.Impl.RemoteScheduler.b__6(IRemotableQuartzScheduler x) +8 Quartz.Impl.RemoteScheduler.CallInGuard(Func`2 func) +61
[SchedulerException: 与远程调度程序通信时出错。] Quartz.Impl.RemoteScheduler.CallInGuard(Func`2 func) +100 Quartz.Impl.RemoteScheduler.get_SchedulerName() +92 Quartz.Impl.SchedulerRepository.Bind(IScheduler sched) +65 Quartz .Impl.StdSchedulerFactory.Instantiate() +1815 Quartz.Impl.StdSchedulerFactory.GetScheduler() +102 ASP.global_asax.Application_Start(Object sender, EventArgs e) +241
[HttpException (0x80004005): 与远程调度程序通信时出错。] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9189101 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339 System.Web.Hosting.PipelineRuntime.InitializeApplication( IntPtr appContext) +253
[HttpException (0x80004005): 与远程调度程序通信时出错。] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9104200 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext 上下文)+256
在此之后,如果我转到服务器,并停止/启动 Quartz.net 服务,那么该站点将正确启动。
每次我通过 FTP 上传修改的 web.config 或修改的另一个文件时都会发生同样的事情,这会导致网站重新启动。在这里我得到了同样的错误,我可以绕过停止和重新启动 Quartz.net 服务。
这是网站的global.asax:
public static ISchedulerFactory SchedulerFactory;
public static IScheduler Scheduler;
void Application_Start(object sender, EventArgs e)
{
NameValueCollection p = new NameValueCollection();
p["quartz.scheduler.instanceName"] = "MyScheduler";
p["quartz.scheduler.proxy"] = "true";
p["quartz.threadPool.threadCount"] = "0";
p["quartz.scheduler.proxy.address"] = "tcp://localhost:555/QuartzScheduler";
SchedulerFactory = new StdSchedulerFactory(p);
Scheduler = SchedulerFactory.GetScheduler(); // <-- The exception seems to occur here
if (!Scheduler.IsStarted)
Scheduler.Start();
}
void Application_End(object sender, EventArgs e)
{
Scheduler.Shutdown(true);
}