Update the UI using a delegate in a Windows Phone development thread

Source: Internet
Author: User

References:

Http://www.cnblogs.com/xqiwei/archive/2012/02/16/2353870.html

Instance description:
In Windows Phone development, the use of threads is somewhat different from others, and the use of threads is combined with delegation.
In mainpage, there is only one button and textblock, and the content of textblock is updated every two seconds through the thread.
The Code is as follows:

Public partial class mainpage: phoneapplicationpage {delegate void mydelegate (); // The thread delegates mydelegate = NULL; // The delegate instantiates static string temp = ""; // variable updated during the loop // constructor public mainpage () {initializecomponent () ;}/// <summary> // function: update UI /// </Summary> Public void updatetextblock () {This. textblock1.text = "the number of cycles is =" + temp;} // <summary> // function: thread, updates are implemented cyclically at intervals. // </Summary> Public void mythread () {int I = 0; while (I <5) {temp = I. tostring (); this. dispatcher. begininvoke (mydelegate); thread. sleep (1000*2); I ++ ;}} private void button#click (Object sender, routedeventargs e) {// The thread mydelegate = updatetextblock when loading; thread TT = new thread (New threadstart (mythread); TT. start ();}}

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.