WPF 异步刷新页面,创建定时器
#region 异步,刷新页面 /// <summary> /// 页面加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UserControl_Loaded(object sender, RoutedEventArgs e) { dispatcherTimer.Tick += DispatcherTimer_Tick;//绑定计时器事件 dispatcherTimer.Interval = new TimeSpan(0, 0, 5);//设置时间间隔::每隔1秒刷新页面 dispatcherTimer.Start();//开启运行 } /// <summary> /// 计时器事件:异步执行[刷新当前页面] /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void DispatcherTimer_Tick(object sender, EventArgs e) { Task.Factory.StartNew(AsynchronousRefresh); } /// <summary> /// 刷新当前页面方法 /// </summary> public void AsynchronousRefresh() { Task task = new Task(() => QueryCondition(index, page, true)); task.Start(); } #endregion