Timer Class and C #

I have a program written in C #. I want the Timer class to run the function at a specific time.

For example: start function X at 20:00 pm

How to do this using the Timer class?

+3
source share
5 answers

Use the Timer Tick event to check (check the appropriate box), and then in the tick event:

DateTime Now = DateTime.Now;

if(Now.Hours == DateTimeCallX.Hours 
 && Now.Minutes == DateTimeCallX.Minutes 
 && xHasRan == false)
  {
  x();
  xHasRan = true;
  }

DateTimeCallX - A DateTime object set at 20:00.
xHasRan is a logical expression indicating whether this function was called, it will initially be set to false and will be set to true after x is called, so if the timer timer starts again at that minute, it will not run this function again.

+2
+4

, , . 20:00 , . .

, , System.Threading.Timer .

+2

20:00 , Quartz.NET.

0

, , , , , , .

-1

Source: https://habr.com/ru/post/1714505/


All Articles