This article shares the specific code for WPF timed refresh UI interface display for your reference. The specific content is as follows
Code:
using ; using System; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; namespace { public partial class MainPage : UserControl { private timerNotice = null; public MainPage() { InitializeComponent(); } private void MainPage_Loaded(object sender, RoutedEventArgs e) { #region Notices if (timerNotice == null) { BindNotice(); timerNotice = new (); += new ((o, eea) => { BindNotice(); }); = 60 * 1000; (); } #endregion } private void MainPage_SizeChanged(object sender, SizeChangedEventArgs e) { } #region Binding Notification Announcement private void BindNotice() { (() => { try { int total = 0; TES_NOTICE info = new TES_NOTICE(); IList<TES_NOTICE> list = new List<TES_NOTICE>(); list = <INoticeService>().GetListPage(null, , , 1, 50, ref total); (new Action(() => { = list; })); } catch { } }); } #endregion } }
Note: Using BackgroundWorker in the event is invalid, that is, the following code cannot refresh the interface normally:
using ; using System; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; using ; namespace { public partial class MainPage : UserControl { private timerNotice = null; public MainPage() { InitializeComponent(); } private void MainPage_Loaded(object sender, RoutedEventArgs e) { #region Notices if (timerNotice == null) { BindNotice(); timerNotice = new (); += new ((o, eea) => { BindNotice(); }); = 60 * 1000; (); } #endregion } private void MainPage_SizeChanged(object sender, SizeChangedEventArgs e) { } #region Binding Notification Announcement private void BindNotice() { PT_USER_INFO user = new PT_USER_INFO(); IList<TES_COMBAT_TASK> taskList = new List<TES_COMBAT_TASK>(); BackgroundWorker worker = new BackgroundWorker(); += (s, e) => { user = <>().(); taskList = <ITaskService>().GetCombatTaskByUserIDUnfinished(()); }; += (s, e) => { try { = taskList; } catch { } }; (); } #endregion } }
You can also use DispatcherTimer to refresh the interface, but time-consuming operations cannot be performed in the DispatcherTimer event, otherwise the interface will be stuck. Therefore, time-consuming and time-consuming timed operations, such as querying the database, need to use another one, which is relatively troublesome.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.