C#WPF 启动后到某个时间点定时任务

程序每天都会重新启动到某个时间点就需要执行一个方法
private static string updateTime = ConfigurationManager.AppSettings[“updateTime”];//每天定时启动更新时间
public MainWindow()
{
try
{
TimeSpan dtNow = DateTime.Now.TimeOfDay;

                DateTime start = Convert.ToDateTime(updateTime);

                TimeSpan dt = start.TimeOfDay;

                TimeSpan timeD = dt.Subtract(dtNow);

                timer.Tick += new EventHandler(Time_Tick);

                timer.Interval = new TimeSpan(timeD.Hours, timeD.Minutes, timeD.Seconds);

                timer.Start();
            }
            catch
            {
                Loger.Write("定时更新时间不对");
            }
            }
            private void Time_Tick(object sender, EventArgs e)
    {
        //todo 任务
    }

你可能感兴趣的:(记录)