0
嘿,我有一個WPF應用程序,並使用DispatcherTimer每分鐘觸發一個事件。 我運行我的應用程序和CPU負載跳轉到100%。我試圖在不使用定時器的情況下編譯應用程序,並且cpu的負載非常低,因爲我預期它會是。DispatcherTimer和高CPU負載
樣品的編號:
DispatcherTimer MainTimer = new DispatcherTimer();
MainTimer.Tick += new EventHandler(Core.Timers.MainTimer_Tick);
MainTimer.Interval = TimeSpan.FromSeconds(60);
MainTimer.Start();
public static void MainTimer_Tick(object sender, EventArgs e)
{
// initialize new class, do something...
}
沒有這種代碼CPU負荷低。 這是什麼原因?
更新 我可以使用som其他計時器嗎?準確性並不重要。
在MainTimer_Tick中沒有代碼的情況下CPU負載很低? – STO 2010-06-23 22:05:03
不,這是一樣的。 – daemon 2010-06-23 22:10:52
你確實會因爲_empty_'Tick'處理程序而導致性能下降? – SLaks 2010-06-23 22:12:05