2017-10-17 166 views
-1

我寫在WPF拍賣應用程序,我不知道如何重新啓動我的DispatcherTimer,任何人都可以告訴我如何重新啓動調度計時器在c#wpf應用程序?

這是Timer的代碼。

Timer = new DispatcherTimer(); 

Timer.Interval = new TimeSpan(0,0,1); 

Timer.Tick += Timer_Tick; 

void Timer_Tick(object sender, object e) 
{ 
    if (time > 1) 
    { 
     time--; 
     timertxt.Text = string.Format("00:0{0}:{1}", time/60, time % 60); 

    } 
    else 
    { 
     Timer.Stop(); 
     MessageBox.Show("Auction is off !","Error !",MessageBoxButton.OK,MessageBoxImage.Error); 

     AuctionIDtxt.Clear(); 
     Productnametxt.Clear(); 
     pricetxt.Clear(); 
     descriptiontxtblock.Clear(); 

     winnerislbl.IsVisible.Equals(true); 
     winnerislbl.Content = "winner is:" ; 
     winuserlbl.Content = UserLbl; 

    } 
} 
+0

調用'Timer.Start()'。也就是說,你不應該自己計算秒數,因爲計時器不是任意精確的。改用DateTime和TimeSpan。 – Clemens

+0

我在加載按鈕的代碼中調用了Timer.Start()。 –

回答

相關問題