dispatcherTimer 是SL中很有用的一个计时器对象。也是基础SL 的UI线程
XAML代码:
<UserControl x:Class="Sample.Timer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WIDth="400" Height="200">GrID x:name="LayoutRoot" Background="White"> <!--背景--> Rectangle Fill="Gold" stroke="Black" strokeThickness="3" RadiusX="5" RadiusY="5"/> 显示时间TextBlock ="tbkTimer" WIDth="300"="50" FontSize="30" Foreground="Red"/></GrIDUserControl>
后台代码:
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.windows.Threading;namespace Sample{ public partial class Timer : UserControl {public Timer(){ InitializeComponent(); //创建dispatcherTimer dispatcherTimer timer = new dispatcherTimer(); 设置间隔1秒 timer.Interval = new TimeSpan(0,1); 创建事件处理 timer.Tick += new EventHandler(timer_Tick); 开始计时 timer.Start();}voID timer_Tick(object sender,EventArgs e){ 输出时间 tbkTimer.Text = "当前时间:" + DateTime.Now.TolongTimeString();} }} 总结以上是内存溢出为你收集整理的silverlight中的多线程和计时器全部内容,希望文章能够帮你解决silverlight中的多线程和计时器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)