silverlight 线程委托实现时间控件

silverlight 线程委托实现时间控件,第1张

概述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;us
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 线程委托实现时间控件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1023937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存