The Timer control similar to WinForm is no longer available in WPF. Therefore, you need to use the DispatcherTimer class to implement scheduled execution events similar to Timer. This event is implemented using delegation. DispatcherTimer classIn
In System. Windows. Threading, the using System. Windows. Threading namespace is required.
The following is a simple Sample Code. The Code displays the current system time in real time in the title of the WPF form.
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. Data;
Using System. Windows. Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Imaging;
Using System. Windows. Navigation;
Using System. Windows. Shapes;
Using System. Windows. Threading;
Namespace TimerWindow
{
/// <Summary>
/// Interaction logic for MainWindow. xaml
/// </Summary>
Public partial class MainWindow: Window
{
DispatcherTimer timer = new DispatcherTimer ();
Public MainWindow ()
{
InitializeComponent ();
Timer. Tick + = new EventHandler (timer_Tick );
// Timer. Interval = TimeSpan. FromSeconds (0.1); // set the Refresh Interval
Timer. Start ();
}
Void timer_Tick (object sender, EventArgs e)
{
This. Title = string. Concat ("TimerWindow", DateTime. Now. ToString ("yyyy-MM-dd hh: mm: ss "));
}
}
}