WPF implementation of timed Refresh UI interface Example

Source: Internet
Author: User
This article is mainly for you to introduce the WPF implementation of the regular refresh UI interface features, with a certain reference value, interested in small partners can refer to

The example of this article for everyone to share the WPF timed Refresh UI interface display of the specific code for your reference, the specific content is as follows

Code:

Using nhibernate.criterion;using system;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 timernotic    e = 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, ref total);          Dispatcher.invoke (new Action () = {Noticelistview.itemssource = list;        }));    } catch {}}); } #endregion}}

Description: The use of BackgroundWorker in System.Timers.Timer events is not valid, that is, the following code does not refresh the interface normally:

Using nhibernate.criterion;using system;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 timernotic    e = 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}}

The

can also use the DispatcherTimer refresh interface, but time-consuming operations cannot be performed in DispatcherTimer events, otherwise the interface will be stuck, and then time-consuming timing operations, such as querying the database, require a System.Timers.Timer, comparatively troublesome.

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.