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 ();}}