1

I have an MVC application that send an e-mail periodically using Quartz.NET. Although the published application works properly on IIS, it cannot works after recycling application pool or restarting the application on IIS. Searching on the web I found several post suggesting to make some changes on config files or IIS, but none of them working properly. So, is there any method to solve the problem? I need a solution that can be applied on application side (or on IIS side if it is simple just making a config changes, etc.). I think this is a common problem when keeping an application on IIS, isn't it?
Note: I use Windows Server 2008 and IIS 7.5.

Jack
  • 1
  • 21
  • 118
  • 236
  • 2
    Where is the web application published? ISP or in-house? I've [answered](http://stackoverflow.com/a/31960404) a question about app pools and quartz.net few months ago. – LeftyX Nov 08 '15 at 14:43
  • 1
    @LeftyX Mnay thanks for your reply. Actually you show the possibilities and after that there is meaning to force the Application always to be alive on IIS Server. I published the application on IIS Server and according to your post, I think the best option for me to use Windows Service. So, could you please clarify me what changes should I made? I have an MVC5 Web Application and no idea how to trig the application or Quartz job weekly? I know the Windows Scheduler settings, I just need the other settings that I should do on application, quartz and windows side. Thanks a lot. – Jack Nov 09 '15 at 08:10
  • 1
    This seems like a configuration problem to me. May be application is not completely killed when restarting IIS or may be startup configuration is not 100% correct. Just guessing. – TheTechGuy Nov 09 '15 at 16:57

1 Answers1

2

You do not mention in your question where your application is going to run so I guess it's going to be hosted in-house.

Following your comment I gather you do not have any problems installing and running a Windows Service on your server.

My suggestion - and something I've implemented in the past - is to use the ASP.NET MVC application only as a UI where you create, delete or suspend your jobs/triggers which will be persisted in a database so, whatever happens to your application, you won't lose your jobs/triggers and they will be executed as soon as the application goes back on-line.

The database will be shared with the other layer, the Windows Service, which will be responsible for running your scheduled jobs.

First step is to setup and use AdoJobStore to store Quartz.Net data. As you can see in the post there are a few providers you can use.

Second step is to create and configure your Windows Service. I would use TopShelf to host it. The implementation is very simple and straightforward; plus you can use the Quartz.Net integration provided here.

If you go through the documentation you won't find any problem integrating the solution.

Quartz.Net depends on some configuration you have to add in your app.config/web.config. In this answer there's a detail explanation about the configuration and AdoJobStore.

There are a few things to remember implementing this type of solution.
Your Web Application is going to set the property threadPool to ZeroSizeThreadPool in your config:

<add key="quartz.threadPool.type" value="Quartz.Simpl.ZeroSizeThreadPool, Quartz" />

or in your code:

properties["quartz.threadPool.type"] = "Quartz.Simpl.ZeroSizeThreadPool, Quartz";

and it's never going to start the Scheduler (your windows service is going to use that).

Community
  • 1
  • 1
LeftyX
  • 35,328
  • 21
  • 132
  • 193
  • 1
    Many thanks for your detailed explanations. I just have time to proceed and want to be sure that if it is better for me to use a Console application in addition to MVC app in the same Solution and call this from a windows scheduled task. Because I have tried many things but none of them is working and I really do not want to apply different methods except from the current ones. Any idea for using console application or keeping the application (published to IIS) alive for both Quartz or Hangfire? – Jack Nov 10 '15 at 12:11