-1

I want that when the button is pressed, two numbers one are displayed with an interval of half a second in textbox

But if you do everything as in my example, both numbers are displayed simultaneously in half a second

  private void Button_Click(object sender, RoutedEventArgs e)
        {
            Checker.Text += "1";

            System.Threading.Thread.Sleep(500);

            Checker.Text += "1";
        }

The same will happen with any loop inside any event handler

Verden
  • 9
  • 2

1 Answers1

0

The Thread.Sleep() call will block the Dispatcher thread. Its that thread that updates your UI, in order to do what you want you will need to either run a background worker thread, or more simply use the Async/Await syntax

  private async void Button_Click(object sender, RoutedEventArgs e)
    {
        Checker.Text += "1";

        await Task.Delay(500);

        Checker.Text += "1";
    }
Ben Steele
  • 414
  • 2
  • 10