我需要非常快的计数我的Windows 8商店应用程序。所以我把间隔设为10点。因为我们每秒有10,000,000蜱,这就足够了。但结果我只得到了大约30块。我怎样才能得到更快的计时器?
我的定时器代码(和控制定时器):
int GLOBAL_counter = 0;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromTicks(10);
timer.Tick += timer_Tick;
timer.Start();
DispatcherTimer timerControl = new DispatcherTimer();
timerControl.Interval = TimeSpan.FromSeconds(1);
timerControl.Tick += timer_Tick_timerControl;
timerControl.Start();
}
private void timer_Tick(object sender, object e)
{
GLOBAL_counter++;
}
private void timer_Tick_timerControl(object sender, object e)
{
Label1.Text += GLOBAL_counter.ToString() + "\r\n";
GLOBAL_counter = 0;
}发布于 2013-09-10 10:13:52
来自MSDN对DispatcherTimer类的描述:
计时器不能保证在时间间隔发生时准确执行,但保证它们不会在时间间隔发生之前执行。这是因为与其他操作一样,DispatcherTimer操作被放置在Dispatcher队列上。当执行DispatcherTimer操作时,取决于队列中的其他作业及其优先级。
https://stackoverflow.com/questions/16897941
复制相似问题