1

I want to write windows service which is works every day at 7.00 a clock. But blow code works only two day. I can not find the reason.

TIA!

  logger.Info("OnStart started");
                System.Threading.TimerCallback callback = new System.Threading.TimerCallback(change_wpa);
                var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 0, 0);
                var dt2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day + 1, 0, 0, 0);
                var dt3 = new TimeSpan(24, 0, 0);

                if (DateTime.Now < dt)
                {
                    logger.Info("DateTime.Now < dt");
                    var timer = new System.Threading.Timer(callback, null, dt - DateTime.Now, TimeSpan.FromHours(24));
                }
                else
                {
                    logger.Info("DateTime.Now > dt");
                    var timer = new System.Threading.Timer(callback, null, dt3 - (DateTime.Now - dt), TimeSpan.FromHours(24));
                }
4

0 回答 0