mercredi 26 septembre 2018

Generate random numbers till Button click (UWP)

I have a textblock and a button.

I want the textblock to be filled with a random number when I click the button and it should change the random number every 5 seconds. When I click the button a second time it should stop at the last random number.

How do I make this? This is what I tried:

    bool thisStatus = false;

    private void btn_click(object sender, RoutedEventArgs e)
    {
        if (thisStatus == false)
        {
            thisStatus = true;
        }
        else thisStatus = false;
        random();
    }

        private void random()
    {
        while (thisStatus)
        {
            Random random = new Random();
            int RandomNumber = random.Next(0, 100);
            txtBlck.Text = RandomNumber.ToString();
            Task.Delay(5000);
        }
    }




Aucun commentaire:

Enregistrer un commentaire