DispatcherTimer set up : Timer « Windows Presentation Foundation « C# / CSharp Tutorial






<Window x:Class="_360Timer.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Concentric Rings" Width="910" Height="512">
  <Canvas Name="MainCanvas" Background="#FFE0E0E0"/>
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;


namespace _360Timer
{

    public partial class Window1 : Window
    {
        System.Windows.Threading.DispatcherTimer frameTimer;

        public Window1()
        {
            InitializeComponent();

            frameTimer = new System.Windows.Threading.DispatcherTimer();
            frameTimer.Tick += OnFrame;
            frameTimer.Interval = TimeSpan.FromSeconds(1.0 / 60.0);
            frameTimer.Start();

            this.Show();

        }


        private void OnFrame(object sender, EventArgs e)
        {
        }

    }
}
WPF Dispatcher Timer Set Up








24.118.Timer
24.118.1.Set interval and event handler for DispatcherTimerSet interval and event handler for DispatcherTimer
24.118.2.Update the UI Asynchronously on a TimerUpdate the UI Asynchronously on a Timer
24.118.3.DispatcherTimer set upDispatcherTimer set up