DispatcherTimer vs a regular Timer in WPF app for a task scheduler

后端 未结 3 1427
天涯浪人
天涯浪人 2020-12-05 00:33

Please, explain the difference between \"DispatcherTimer\" and \"a regular Timer\" that @Kent Boogaart meant for using in a multithreading WPF app as a task sheduler in this

3条回答
  •  失恋的感觉
    2020-12-05 00:55

    With .NET 4.5 you can also create an async delegate for your timer if you need to use the new .NET 4.5 await functionality.

            var timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(20);
            timer.Tick += new EventHandler(async (object s, EventArgs a) =>
            {
                Message = "Updating...";
                await UpdateSystemStatus(false);  
                Message = "Last updated " + DateTime.Now;              
            });
            timer.Start();
    

提交回复
热议问题