在silverlight2.0 System.Windows.Threading 命名空间下新增时间器DispatcherTimer ,以替代html中的定时器。
这将更方便我们程序的控制。
以下是定时器的试列:
xmal:
<Grid x:Name="LayoutRoot" Background="White"> <!-- Just a TextBlock to show the output of the timer. --> <TextBlock Loaded="StartTimer" x:Name="myTextBlock" /> </Grid>
C#:
public void StartTimer(object o,RoutedEventArgs sender) { System.Windows.Threading.dispatcherTimer mydispatcherTimer = new System.Windows.Threading.dispatcherTimer(); mydispatcherTimer.Interval = new TimeSpan(0,100); // 100 Milliseconds mydispatcherTimer.Tick += new EventHandler(Each_Tick); mydispatcherTimer.Start(); } // A variable to count with. int i = 0; // Fires every 100 miliseconds while the dispatcherTimer is active. public void Each_Tick(object o,EventArgs sender) { myTextBlock.Text = "Count up: " + i++.ToString(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。