Answer the question
In order to leave comments, you need to log in
How to write a stopwatch in UWP in C#?
I want to write a stopwatch in UWP in C#. In the constructor, I added a button and a text box named label1. Wrote this code:
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Threading.Tasks;
using System.Timers;
using System.Diagnostics;
namespace Stopwatcher
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private static System.Timers.Timer aTimer;
public void MyMain()
{
SetTimer();
}
private void SetTimer()
{
aTimer = new System.Timers.Timer(100);
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
label1.Text = "test";
Debug.WriteLine(e.SignalTime);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MyMain();
label1.Text = "wdfsff";
Debug.WriteLine("CYKA");
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question