timer.Tick += delegate c# does not work



  • There's a code written in Windows Forms:

    DateTime TimeToWorkServerTemp;
    DateTime ServerTemp = DateTime.Now;
     TimeToWorkServerTemp = new DateTime(ServerTemp.Year, ServerTemp.Month, ServerTemp.Day, ServerTemp.Hour, ServerTemp.Minute, 0);
    var ServtempDel = new System.Windows.Forms.Timer { Interval = 1000, Enabled = true };
                ServtempDel.Tick += delegate
            {
                if (TimeToWorkServerTemp < DateTime.Now)
                { что то делается
                        TimeToWorkServerTemp = TimeToWorkServerTemp.AddMinutes(1);
                    ServtempDel.Enabled = true;
                }
            };
    

    The problem is, Windows Form, he's doing a good job, and if you use console, the code doesn't work, tell me why?



  • The reason is this System.Windows.Forms♪ Timer

    Use it. System.Threading.Timer In the sunflower applications and WinForms, too. Or System.Timers.Timerlike the commentaries.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2