【背景】服務器
一個pivot中有三個pivotItem項,每一個pivot中有一個listbox,pivot每次切換的時候都會向服務器端請求數據,致使UI很卡ide
【解決方法】函數
經過DispatcherTimer控制請求的頻度。spa
【代碼】code
1 private DispatcherTimer timer; 2 3 構造函數(){ 4 // 經過計時器控制請求,防止每次pivot改變就直接請求。 5 timer = new DispatcherTimer(); 6 timer.Interval = TimeSpan.FromMilliseconds(600); 7 timer.Tick += timer_Tick; 8 } 9 10 11 void timer_Tick(object sender, EventArgs e) 12 { 13 timer.Stop(); 14 //ToDo... 請求 15 } 16 17 private void Search() 18 { 19 timer.Stop(); 20 timer.Start(); 21 }