You need to take the date from the dt_send_daytime column. Ie 1: 1: 4: 0 every week, every Monday, at one o'clock, 4 minutes it should work. Can I do this?

enter image description here

Where is the date put?

  foreach(DataRow row in dt.Rows) { MyTimer myTimer = new MyTimer(); string dt_str = row["shedule_dt_send_daytime"].ToString(); string[] dt_str_tmp = dt_str.Split(':'); switch (row["time_name_ru"].ToString().ToUpper()) { case "ЧАС": Console.WriteLine(dt_str_tmp[2] + ":" + dt_str_tmp[3]); //мм:сс break; case "НЕДЕЛЯ": Console.WriteLine(dt_str_tmp[0] + ":" + dt_str_tmp[1]); //дд:чч break; case "ДЕНЬ": Console.WriteLine(dt_str_tmp[1] + ":" + dt_str_tmp[2]); //чч:мм break; case "МИНУТ": Console.WriteLine(dt_str_tmp[3]); //сс break; } // вот тут надо что-то вставить myTimer.datetime = Convert.ToDateTime(row["shedule_dt_send_daytime"]); myTimer.alg = Convert.ToString(row["meta_cod"]); // myTimer.Dt_Begin = Convert.ToDateTime(row["shedule_dt_beg"]); // myTimer.Dt_Period_End = row["shedule_dt_period_end"]; myTimer.Interval = Convert.ToInt32(dt_str_tmp); myTimer.Elapsed += OnTimeout; myTimer.AutoReset = true; myTimer.Enabled = true; } 

  • In the "hour and 4 minutes" or in the "hour" to work 4-minutes? - MaximK
  • This is the interval time: every Monday, at one o'clock and 4 minutes 0 seconds - propro17

1 answer 1

Sure you may!

  1. When a program / function launch occurs, you determine the day of the week today.

      int today = (int)DateTime.Now.DayOfWeek; 

Details: A practical guide. Extract the day of the week from a specific date

  1. Having determined the day, you go through all the rows in the table and check whether the first character in the dt_send_daytime column dt_send_daytime number of the day of the week you received. If yes, then start the timer with the necessary parameters.

     if (today == dt_str_tmp[0]) { // создаешь таймер } 

UPDATE : Insert after switch

  • I cannot do this) Help? - propro17
  • @ propro17: What exactly can you not? - VladD
  • @ propro17 yes you already have everything. It remains to get the day of the week - MaximK
  • @MaximK Show me please. I just don’t know how to do it (does the first character correspond). Updated the question - - propro17
  • yes everything is simple ... строковая_переменна[номер_символа] - MaximK