I am not sure what is wrong with my code can someone help fix the error? The error is in the timer.Tick() line. It's supposed to make a stopwatch.
namespace App3
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private int myCount;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += new EventHandler<object>(timer_Tick);
timer.Interval = TimeSpan.FromSeconds(5);
timer.Start();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
}
private void timer_Tick(object sender, EventArgs e)
{
myCount++;
Label.Text = myCount.ToString();
}
}
DispatcherTimer.Tick is an EventHandler, not an EventHandler<object>.
You need to change your code to specify this correctly:
timer.Tick += new EventHandler(timer_Tick);
Note that this can also be written in short form, which is typically safer:
timer.Tick += timer_Tick;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With