close

在WPF中如果需要用到Timer 則可以使用DispatcherTimer。

透過這個Timer,可以直接改變視窗上資料呈現,若使用其他種Timer的話則要進一步使用Dispatcher才能夠實現囉!!

講到Timer,.NET裡面有一大堆各式各樣不同的Timer可以使用,詳細用法之後有空再補囉^^!!!

 

用法如下

using System.Windows.Threading;

static void Main(){
    //宣告Timer
     DispatcherTimer _timer = new DispatcherTimer();

    //設定呼叫間隔時間為30ms
    _timer.Interval = TimeSpan.FromMilliseconds(30);

    //加入callback function
    _timer.Tick += _timer_Tick;

    //開始
    _timer.Start();
}

void _timer_Tick(object sender, EventArgs e)
{
    //do something here!!
}

 

參考資料

Comparing the Timer Classes in the .NET Framework Class Library

 

arrow
arrow
    文章標籤
    C# WPF Timer
    全站熱搜

    Chris 發表在 痞客邦 留言(0) 人氣()