0

I'm trying to run a function every day at 11:30.

private void timer1_Tick(object sender, EventArgs e)
{
    timer1.Interval = 1000;
    if (DateTime.Now.Hour == 11 && DateTime.Now.Minute == 30)
    {
        run_dtsx(path, false); 
    }
}

The function is not running, and I can't figure out why.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
sqlerty
  • 27
  • 3
  • Read [ask] and create a [mcve]. From the code shown we can't tell anything. For starters, did you start the timer? – CodeCaster Jan 03 '16 at 10:41
  • Take the "timer1.Interval = 1000" out of the event handler. You need to set that once after the creation of the timer. Then make sure your if block only runs once and not 59 times :-) – Martin Maat Jan 03 '16 at 10:44
  • 2
    [How to call a method daily, at specific time, in C#?](http://stackoverflow.com/q/3243348/447156) – Soner Gönül Jan 03 '16 at 10:45
  • 1
    @Erno, I agree that [that question](http://stackoverflow.com/q/3243348/447156) explains how to do it properly, but it's not how duplicates work. OP is asking _"How to fix this code"_ (which can currently not be answered), and you're saying _"Don't bother, use this approach instead"_. That's fine as a comment, but not as duplicate target. – CodeCaster Jan 03 '16 at 10:48
  • 2
    @CodeCaster That's why I put it as a comment, not voted as a duplicate :) – Soner Gönül Jan 03 '16 at 10:49
  • 1
    @FᴀʀʜᴀɴAɴᴀᴍ I did not, that's just how the close message displays it. I closed as non-repro. – CodeCaster Jan 03 '16 at 10:49
  • @CodeCaster I didn't know that. It seems the closed message is misleading : `marked as duplicate by CodeCaster, Mat, Erno de Weerd c# 3 mins ago` – Fᴀʀʜᴀɴ Aɴᴀᴍ Jan 03 '16 at 10:50
  • @FᴀʀʜᴀɴAɴᴀᴍ Probably @CodeCaster voted to close it with some different option but since Erno has special power to close `c#` tagged questions, it shows as a "duplicate message" in the result. – Soner Gönül Jan 03 '16 at 10:52

0 Answers0