WPF implements regular UI refreshing and wpf refreshes the ui.
The examples in this article share with you the specific code displayed on the wpf ui for regular refresh for your reference. The specific content is as follows:
Code:
Using nhib.pdf. criterion; using System. collections. generic; using System. collections. objectModel; using System. componentModel; using System. data; using System. linq; using System. text; using System. threading; using System. windows; using System. windows. controls; using System. windows. data; using System. windows. documents; using System. windows. input; using System. windows. media; using System. windows. media. imaging; using System. windows. navigation; using System. windows. shapes; using Visifire. charts; namespace SunCreate. combatPlatform. client {public partial class MainPage: UserControl {private System. timers. timer timerNotice = null; public MainPage () {InitializeComponent ();} private void MainPage_Loaded (object sender, RoutedEventArgs e) {# region notification announcement if (timerNotice = null) {BindNotice (); timerNotice = new System. timers. timer (); timerNotice. elapsed + = new System. timers. elapsedEventHandler (o, eea) =>{ BindNotice () ;}); timerNotice. interval = 60*1000; timerNotice. start () ;}# endregion} private void MainPage_SizeChanged (object sender, SizeChangedEventArgs e) {}# region binding notification announcement private void BindNotice () {System. threading. tasks. task. factory. startNew () => {try {int total = 0; TES_NOTICE info = new TES_NOTICE (); IList <TES_NOTICE> list = new List <TES_NOTICE> (); list = HI. get <INoticeService> (). getListPage (null, DateTime. minValue, DateTime. minValue, 1, 50, ref total); Dispatcher. invoke (new Action () => {noticeListView. itemsSource = list;});} catch {}}) ;}# endregion }}
Note: Using BackgroundWorker in the System. Timers. Timer event is invalid, that is, the following code cannot refresh the interface normally:
Using nhib.pdf. criterion; using System. collections. generic; using System. collections. objectModel; using System. componentModel; using System. data; using System. linq; using System. text; using System. threading; using System. windows; using System. windows. controls; using System. windows. data; using System. windows. documents; using System. windows. input; using System. windows. media; using System. windows. media. imaging; using System. windows. navigation; using System. windows. shapes; using Visifire. charts; namespace SunCreate. combatPlatform. client {public partial class MainPage: UserControl {private System. timers. timer timerNotice = null; public MainPage () {InitializeComponent ();} private void MainPage_Loaded (object sender, RoutedEventArgs e) {# region notification announcement if (timerNotice = null) {BindNotice (); timerNotice = new System. timers. timer (); timerNotice. elapsed + = new System. timers. elapsedEventHandler (o, eea) =>{ BindNotice () ;}); timerNotice. interval = 60*1000; timerNotice. start () ;}# 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 (); worker. doWork + = (s, e) =>{ user = HI. get <Cache. ICacheService> (). userCache. getCurrentUserInfo (); taskList = HI. get <ITaskService> (). getCombatTaskByUserIDUnfinished (user. ID. toString () ;}; worker. runWorkerCompleted + = (s, e) => {try {taskListView. itemsSource = taskList;} catch {}}; worker. runWorkerAsync () ;}# endregion }}
You can also use the DispatcherTimer interface to refresh the interface. However, time-consuming operations cannot be executed in the DispatcherTimer event. Otherwise, the interface will be stuck, so time-consuming scheduled operations, such as database query, need to use another System. timers. timer, relatively troublesome.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.