using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;using System.Threading;namespace SilverlightApplication28{ public partial class MainPage : UserControl { private Thread myThread = null;//定义线程 private delegate voID MyDelegate(object param);//定义委托 private StackPanel TestStackPanel = null; private button Testbutton = null; private TextBlock TestTextBlock = null; public MainPage() { InitializeComponent(); TestStackPanel = new StackPanel(); TestStackPanel.VerticalAlignment = VerticalAlignment.Center; TestStackPanel.HorizontalAlignment = HorizontalAlignment.Center; LayoutRoot.Children.Add(TestStackPanel); Testbutton = new button(); Testbutton.WIDth = 200; Testbutton.Height = 24; Testbutton.Content = "Test"; Testbutton.Click += new RoutedEventHandler(Testbutton_Click); TestStackPanel.Children.Add(Testbutton); TestTextBlock = new TextBlock(); TestStackPanel.Children.Add(TestTextBlock); } voID Testbutton_Click(object sender,RoutedEventArgs e) { string str = "welcome:"; myThread = new Thread(ThreadMethod); myThread.Start(str); } private voID ThreadMethod(object param) { MyDelegate myDelegate = new MyDelegate(DelegateMethod); while (true) { this.dispatcher.BeginInvoke(myDelegate,param); Thread.Sleep(1000); } } private voID DelegateMethod(object param) { TestTextBlock.Text = param + DateTime.Now.ToString(); } }}总结
以上是内存溢出为你收集整理的silverlight 线程委托实现时间控件全部内容,希望文章能够帮你解决silverlight 线程委托实现时间控件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)