Error DispatcherTimer C # (Universal app win 10)

0

I'm new to programming and I was able to do this code with help, but an error is occurring. follow image.

public sealed partial class MainPage : Page
{
    private MySqlConnection _connection;

    DispatcherTimer mytimer = new DispatcherTimer();
    int currentcout = 0;

    public MainPage()
    {
        this.InitializeComponent();
        mytimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
        mytimer.Tick += new EventHandler(mytimer_Tick);
    }

    private void mytimer_Tick(object sender, EventArgs e)
    {

    }
}

Thereisstillanerror,evenwithchangesthathavebeenmadebyyourcolleaguebefore.

    
asked by anonymous 11.03.2017 / 02:33

2 answers

0

Try this:

private readonly DispatcherTimer _mytimer = new DispatcherTimer();
public MainPage()
{
    InitializeComponent();
    _mytimer.Interval = new TimeSpan(0, 0, 0, 5, 0);
    _mytimer.Tick += Mytimer_Tick;
    _mytimer.Start();
}

private void Mytimer_Tick(object sender, object e)
{
    Debug.WriteLine($"executado: {DateTime.Now}");
}

Note: You must use the _mytimer.Start(); method to start Timer

    
11.03.2017 / 15:53
0

In my tests I made some changes and it worked.

Replace:

mytimer.Tick += new EventHandler(mytimer_Tick);

by:

mytimer.Tick += mytimer_Tick;

And replace the mytimer_Tick method signature.

private void mytimer_Tick(object sender, EventArgs e)

by:

private void mytimer_Tick(object sender, object e)
    
11.03.2017 / 03:01