How to use timer

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
Arunchand
Posts: 2
Joined: Thu Dec 29, 2016 3:59 am

How to use timer

Postby Arunchand » Thu Dec 29, 2016 4:02 am

I need to implement timer for auto referesh the html output.How to do it?

JS-Support @Userware
Site Admin
Posts: 1093
Joined: Tue Apr 08, 2014 3:42 pm

Re: How to use timer

Postby JS-Support @Userware » Thu Dec 29, 2016 7:48 am

Hi,

Sure. Here is an example.

Simply put the code below in MainPage.xaml and MainPage.xaml.cs to check it out:

XAML CODE:

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>

C# CODE:

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();
}


Regards,
JS-Support


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 4 guests