1

I need a method to pause my code for a certrain time like: Sleep(1000)

I found Thread.Sleep(); but it only pauses the GUI and my programm runs in the background. Furthermore I found some timer functions that only work in windows form, not in WPF.

The answers from this feed didn´t work as well: How to put delay before doing an operation in WPF

None of them shows a error message but also none of them delays my programm.

//The code I want to run:

  for (int i = 5; i>0; i--)
            {
                win_label_test.Content = i;
                Sleep(1000);
            }

//The Code I used that didn´t work

Thread.Sleep(1000);

//Only pauses the GUI not the programm so there is no output and after 5 seconds it displays "1"

    Task.WaitAll(new Task[] { Task.Delay(2000) });

// Same problem as with Thread.Sleep();
Luca
  • 11
  • 2
  • 2
    How did you manage to translate `await Task.Delay(2000);` (from the answer to the duplicate question) into `Task.WaitAll(new Task[] { Task.Delay(2000) });`, which makes no sense at all? – Clemens Nov 14 '22 at 13:55
  • Maybe we should start by clearing up _what exactly_ needs to be "delayed"? (And why...) – Fildor Nov 14 '22 at 15:41

0 Answers0