title: Best way to shut down program after certain time
body: <p>I am working with a console application that scans multiple image directories and re-sizes then saves images if they exceed a certain size. Once a directory is finished processing a log is then pushed to a web-service page. </p>
  
  <p>This utility program will be run at night for a given number of hours but must be shut down before normal office hours the following day, regardless of if it finished processing the current folder. </p>
  
  <p>I am aware of 3 options to shut the program down:</p>
  
  <ol>
  <li>Via <strong>Scheduled task</strong> setting "shut down after X hours": The concern I have with this option is that it might potentially close the program in the middle of the process, such as between saving the image and logging to the server.</li>
  <li>After processing each image <strong>check the <code>DateTime</code></strong> and if after certain time close it</li>
  <li><strong>User a <code>Timer</code></strong>, set tick to a few hours, once tick handler is called then set a bool flag to false. After processing each image check the bool flag to see if it is time to shut the program down.</li>
  </ol>
  
  <p>Does the timer option have a performance advantage over comparing DateTime?</p>
  
  <p>Is there perhaps an even better way? Maybe I am missing something?</p>