Using DispatcherTimer to trigger event : Dispatcher « Windows Presentation Foundation « C# / CSharp Tutorial






using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;


    public class MainClass : Window
    {
        RadialGradientBrush brush;
        double angle;
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new MainClass());
        }
        public MainClass()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Width = 400;      
            Height = 400;

            brush = new RadialGradientBrush(Colors.White, Colors.Blue);
            brush.Center = brush.GradientOrigin = new Point(0.5, 0.5);
            brush.RadiusX = brush.RadiusY = 0.10;
            brush.SpreadMethod = GradientSpreadMethod.Repeat;
            Background = brush;

            DispatcherTimer tmr = new DispatcherTimer();
            tmr.Interval = TimeSpan.FromMilliseconds(100);
            tmr.Tick += TimerOnTick;
            tmr.Start();
        }
        void TimerOnTick(object sender, EventArgs args)
        {
            Point pt = new Point(0.5 + 0.05 * Math.Cos(angle),0.5 + 0.05 * Math.Sin(angle));
            brush.GradientOrigin = pt;
            angle += Math.PI / 6;      // ie, 30 degrees
        }
    }








24.124.Dispatcher
24.124.1.Unblock Thread with Dispatcher.BeginInvokeUnblock Thread with Dispatcher.BeginInvoke
24.124.2.DispatcherTimer and EventHandlerDispatcherTimer and EventHandler
24.124.3.Dispatcher.BeginInvoke with DispatcherPriority.NormalDispatcher.BeginInvoke with DispatcherPriority.Normal
24.124.4.Use DispatcherTimer to change Dependency PropertyUse DispatcherTimer to change Dependency Property
24.124.5.Dispatcher ExamplesDispatcher Examples
24.124.6.Using a DispatcherTimerUsing a DispatcherTimer
24.124.7.MailDispatcher and NotifyIconMailDispatcher and NotifyIcon
24.124.8.Using DispatcherTimer to trigger event