DispatcherTimer 和高 CPU 负载
嘿,我有一个 WPF 应用程序,并使用 DispatcherTimer 每分钟触发一个事件。 我运行我的应用程序,CPU 负载跳至 100%。我尝试在不使用计时器的情况下编译应用程序,并且 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 负载就会很低。 这应该是什么原因造成的呢?
更新 我可以使用其他计时器吗?准确性并不重要。
Hey, I have an WPF application and using DispatcherTimer to fire an event every minute.
I run my app and the cpu load jumps to 100%. I tried to compile an app without using a timer and cpu load was very low as I it expected to be.
Sample code:
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...
}
Without that code cpu load is low.
What should cause this?
Update
Can I use som other timer? Accuracy isnt important.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 System.Timers.Timer 解决了这个问题。它的行为正确。
I solved this with using System.Timers.Timer. It's behaving correctly.