首页 > 解决方案 > CrystalQuartz 在作为 Windows 服务运行时不工作

问题描述

我在我的石英调度程序项目中添加了水晶石英以显示仪表板(检查链接)。当我将应用程序作为控制台应用程序运行时,下面的代码工作正常。但是当我们将它作为 Windows 服务部署在同一台机器上时它不起作用。它甚至没有抛出任何异常或任何登录事件记录器。

IScheduler scheduler = SetupScheduler();
                Action<IAppBuilder> startup = app => 
                {
                    app.UseCrystalQuartz(scheduler);
                };

                Console.WriteLine("Starting self-hosted server...");
                using (WebApp.Start("http://localhost:9000/", startup))
                {
                    Console.WriteLine("Server is started");
                    Console.WriteLine();
                    Console.WriteLine("Check http://localhost:9000/quartz to see jobs information");
                    Console.WriteLine();

                    Console.WriteLine("Starting scheduler...");
                    scheduler.Start();

                    Console.WriteLine("Scheduler is started");
                    Console.WriteLine();
                    Console.WriteLine("Press [ENTER] to close");     
                    Console.ReadLine();     
                }

                Console.WriteLine("Shutting down...");
                scheduler.Shutdown(waitForJobsToComplete: true);
                Console.WriteLine("Scheduler has been stopped");

当我们将应用程序部署为 Windows 服务时,在浏览器中打开链接“无法访问此站点”时出现以下错误。但是当我们将它作为控制台运行时它工作正常。

标签: c#windows-servicesconsole-applicationschedulerquartz.net

解决方案


最后,我通过将 console.readline 替换为下面的代码来解决它

System.Threading.ManualResetEvent ojbManualResetEvent = new System.Threading.ManualResetEvent(false);
                ojbManualResetEvent.WaitOne();

推荐阅读