Windows服务计时器只能工作两次

时间:2012-06-05 06:04:43

标签: windows-services

我想写一个每天早上7点钟工作的Windows服务。但是打击代码只工作了两天。我找不到原因。

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));
                }

0 个答案:

没有答案