title: Proper way to schedule a task daily in C# .NET web application
body: <p>I have an ASP.NET MVC app that let users store media like videos and photos.</p>
  
  <p>The application also lets the users delete those media stored in the server. To do so i want to implement a "two steps" process in which first (when the media is selected to be deleted), the media entry at the database will get a timestamp that indicates that the entry has to be deleted in some time (a month for example); if that timestamp is not removed in that time, there should be a scheduled method that executes daily and checks if a media entry has a timestamp old enough to be deleted.</p>
  
  <p>My question is about the scheduler:
  I've readed that there are some frameworks like FluentScheduler or Quartz.NET to implement that kind of jobs. Since the application is a web application deployed in IIS, i'm afraid to not use the proper way, framework or method to implement it. Since IIS could shutdown my application at any time and since the scheduled method would execute writes to DB and to the IO File system to delete the db entries and the physical files, it is vital to me that the method executes completely or does not execute at all, to keep the db consistent with the files stored at hd.</p>
  
  <p>My first bet is for FluentScheduler, but i need to know if using frameworks like that is the best solution.</p>
  
  <p>I know that this kind of questions are not welcome in StackOverflow. It is not an opinion question, i just want to read the solutions and select the one that best fits my requirements.</p>
  
  <p>Here is some kind of pseudo-code of what would be inside the scheduled method:</p>
  
  <pre><code>using(ViewMediaDBUnitOfWork uw = new ViewMediaDBUnitOfWork())
          {
              var today = DateTime.Now.Date;
  
              List&lt;Media&gt; mediaToDelete = uw.MediaRepository.Get(m =&gt; (m.ToDelete - today).value.Days &gt; 30);
              mediaToDelete.ForEach(m =&gt;
              {
                  try
                  {
                      //Deletes from DB
                      uw.MediaRepository.Delete(m);
                      //Deletes the file
                      File.Delete(m.Path);
                      //If everything is ok, savechanges
                      uw.MediaRepository.SaveChanges();
                  }
                  catch(Exception e)
                  {
                      LogManager.GetCurrentClassLogger().Error("Error deleting. " + m.Path, e);
                  }                    
              });
          }
  </code></pre>