title: Windows scheduler API with console application Vs .net scheduler tools with asp.net mvc to execute long running processes inside my asp.net MVC
body: <p>I am working on an asp.net mvc-5 web application, deployed under windows 2012 &amp; iis-8. my asp.net mvc have many CRUD operations which are implemented as action methods inside my asp.net mvc.
  But my asp.net mvc web application will be doing scheduled long running network scan process, the network scan will mainly do the following steps:-</p>
  
  <ol>
  <li>Get the list of our servers and vms from our database.</li>
  <li>Get the scanning username and password for each server and vm from a third party tool, using Rest API.</li>
  <li>Call some powershell scripts to retrieve the servers &amp; vms info such as network info, memory, name, etc.</li>
  <li>Update our ERP system with the scan info using Rest API.</li>
  </ol>
  
  <p>Now I did a pilot project using the following approach:-</p>
  
  <ul>
  <li>I define a Model method inside my asp.net mvc to do the above 4 steps.</li>
  <li>Then I install hangfire tool which will be calling the scan method on predefined scheduler.</li>
  <li>Also I create a View inside my asp.net mvc which allow users to set the hangfire schedule settings (this require to do an IIS reset on the host server for hangfire to get the new settings).</li>
  </ul>
  
  <p>Now I run a test scan for a round 150 servers which took around 40 minutes to complete , and it worked well. The only thing I noted is that if I set the schedule to run on non-business hours (where no activity is made on IIS) then hangfire will not be able to call the job, and once the first request is made the missed jobs will run. I overcome this limitation by defining a windows task which calls IIS  each 15 minutes, to keep application pool live, and it worked well...</p>
  
  <p>Now the other approach I am reading about is doing my above is as follow:-</p>
  
  <ol>
  <li>Instead of defining Model method inside asp.net mvc to do the scan, I can create a separate console application to do the scan.</li>
  <li>Then inside my asp.net mvc to create a view which allow users to create and schdule a task inside the windows tasks scheduler. I can do so by integrating with the windows task scheduler API.</li>
  <li>Where this windows task will be calling the console application.</li>
  </ol>
  
  <p>Now I am not sure which approach is better and why ? now generally speaking long running/background jobs should not run under iis.. But at the same time defining these long running processes as console app and calling these apps inside windows task scheduler will create extra dependencies on my web application. And will add extra effort when moving the application from move server to another (for example from test to live)..
  Beside this I read that tools such as hangfire, quartz and other are designed to allow running long running tasks inside IIS and they eliminate the need to create console applications and scheduling these console applications using task scheduler ..
  So can anyone advice on this?</p>