title: How to execute code at a given time every day?
body: <p>I am trying to add a feature to my program that will execute code every day after the closing of the futures markets in Chicago. This means that I want to run code at around 5:35 Eastern Time (4:35 Central Time where the markets are located). This of course will be switching back and forth between EST (UTC -5) and EST (UTC -4) as Daylight Saving Time occurs.</p>
  
  <p>I know there are many similar questions, however none of them seem to offer a solution that I can use. The primary suggestions seem to be to use the Task Scheduler or Quartz, however, I am unable to implement those in my program. I think that the most promising solution would be to use a combination of <code>TimeZoneInfo</code>, <code>DateTime</code>, and <code>TimeSpan</code> to schedule a timer every day that will trigger at the right time. The solution I currently have is this:</p>
  
  <pre><code>    DateTime now = DateTime.Now;
      DateTime currentDateTime = now.DateTime.Date;
      DateTime expiryDateTime = currentDateTime
          .AddHours(17)
          .AddMinutes(35)
          .AddDays(
              now.DateTime.Hour &gt;= 18 + utcOffset 
              || (now.DateTime.Hour == 17 &amp;&amp; now.DateTime.Minute &gt;= 35) ? 1 : 0);
      Timer timer = new Timer(
           ...,
           null,
           expiryDateTime - DateTime.Now,
           ...);
  </code></pre>
  
  <p>I think this this will fall apart, however, if my code is run in a time zone other than Eastern Time. I'm also concerned that this will not behave properly on the 23 or 25 hour days that occur when the time zone switches from EST to EDT and visa versa.</p>
  
  <p>Is there a better way than what I am currently doing to handle the scheduling? How can I make this code more robust to handle being run in any time zone but always execute at the same time in Eastern Time?</p>
  
  <p><strong>EDIT:</strong> As mentioned above, <strong>Task Scheduler and Quartz are not options</strong>. Quartz is out because I am unable to include third party libraries. Task Scheduler is out because I need access to a lot of internal values from my program. Launching another application and exposing those values to that application adds way more complexity than I think this merits. </p>