WPF implements regular UI refreshing and wpf refreshes the ui.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.