Dispatchertimer C# error (Universal app win 10)

Asked

Viewed 66 times

-1

I am new to programming and I was able to make this code with help, only there is an error. follow picture.

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)
    {

    }
}

inserir a descrição da imagem aqui


Still error, even with the amendments passed by the previous colleague.

inserir a descrição da imagem aqui

1 answer

0


Try it this way:

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

Obs: The method should be used _mytimer.Start(); to start the Timer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.