How to use timer
Posted: Thu Dec 29, 2016 4:02 am
I need to implement timer for auto referesh the html output.How to do it?
Code: Select all
<StackPanel Orientation="Horizontal">
<Button Content="Click to Start" Background="#FFE44D26" Click="ButtonToStartTimer_Click"/>
<Button Content="Click to Stop" Background="#FFE44D26" Click="ButtonToStopTimer_Click"/>
<TextBlock Text="0" x:Name="CounterTextBlock" FontSize="26"/>
</StackPanel>
Code: Select all
_dispatcherTimer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 100) };
_dispatcherTimer.Tick += OnTick;
void ButtonToStartTimer_Click(object s, RoutedEventArgs e)
{
_dispatcherTimer.Start();
}
void ButtonToStopTimer_Click(object s, RoutedEventArgs e)
{
_dispatcherTimer.Stop();
}
void OnTick(object s, object e)
{
CounterTextBlock.Text = (int.Parse(CounterTextBlock.Text) + 1).ToString();
}