简体   繁体   中英

XAML DispatcherTimer Interval Too Slow

I need to count very fast for my Windows 8 Store Application. So i set the interval to 10 Ticks. As we have 10,000,000 ticks per second that should be enough. But i only get around 30 ticks as a result. How do i get a faster timer?

My code for the timer (and control timer):

    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;
    }

From MSDN description of DispatcherTimer class:

Timers are not guaranteed to execute exactly when the time interval occurs, but they are guaranteed to not execute before the time interval occurs. This is because DispatcherTimer operations are placed on the Dispatcher queue like other operations. When the DispatcherTimer operation executes is dependent on the other jobs in the queue and their priorities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM