Code has to do one thing first, then wait a couple of seconds, then continue

python wait()
javascript sleep
javascript wait
python delay without sleep
javascript wait 1 second
python wait until
javascript sleep function
react sleep

I'm making a memorygame and I want, when 2 cards are clicked, that they turn around again and sho their backs. As you can see in my code, I'm counting the clicks and when "NumberOfCLicks" hits 2, the "resetCards" method is called. It does what it's supposed to do, turning both cards, but won't show the front of the second card first before turning them again.

My code:

public class MemoryGrid
    private Grid grid;
    private int rows, cols;

    public MemoryGrid(Grid grid, int rows, int cols)
        this.grid = grid;
        this.rows = rows;
        this.cols = cols;


    private void InitializeGrid()
        for (int i = 0; i < rows; i++)
            grid.RowDefinitions.Add(new RowDefinition());
        for (int i = 0; i < cols; i++)
            grid.ColumnDefinitions.Add(new ColumnDefinition());

    private void AddImages()
        List<ImageSource> images = GetImagesList();
        for (int row = 0; row < rows; row++)
            for (int col = 0; col < cols; col++)
                Image back = new Image();
                back.Source = new BitmapImage(new Uri("/images/back.png", UriKind.Relative));

                back.MouseDown += new System.Windows.Input.MouseButtonEventHandler(CardClick);

                back.Tag = images.First();
                Grid.SetColumn(back, col);
                Grid.SetRow(back, row);

    static int numberOfClicks = 0;
    private Image card;
    static int score;
    private Image Image1;
    private Image Image2;

    private void CardClick(object sender, MouseButtonEventArgs e)
        Image card = (Image)sender;
        ImageSource front = (ImageSource)card.Tag;
        card.Source = front;


    private void checkCards(Image card)

        this.card = card;
        if (numberOfClicks < 2 || numberOfClicks == 2)

            if (this.Image1 == null)
                Image1 = card;
            else if (this.Image2 == null)
                Image2 = card;

        if (numberOfClicks == 2)

            numberOfClicks = 0;
            Image1 = null;
            Image2 = null;

    public void checkPair()
        resetCards(Image1, Image2);
       // more code here to check if the 2 cards are a pair.
       // First only a reset after 2 cards.

    private void resetCards(Image card1, Image card2)
        this.Image1 = card1;
        this.Image2 = card2;

        card1.Source = new BitmapImage(new Uri("/images/back.png", UriKind.Relative));
        card2.Source = new BitmapImage(new Uri("/images/back.png", UriKind.Relative));

    public List<ImageSource> GetImagesList()
        List<ImageSource> images = new List<ImageSource>();
        List<string> random = new List<string>();

        for (int i = 0; i < 16; i++)

            int imageNR = 0;

            Random rnd = new Random();
            imageNR = rnd.Next(1, 17);
            if (random.Contains(Convert.ToString(imageNR)))
                ImageSource source = new BitmapImage(new Uri("images/" + imageNR + ".png", UriKind.Relative));
        return images;

Attila and the Battle Cruiser, The signal lantern clattered for a few seconds and then the men waited until the until first light and assess the gathering of ships that I expect will be waiting for us. group and the powers that be at Kriegsmarine, the code for the untruth is the We have devised several other methods of saying one thing and imparting​  The JavaScript interpreter will encounter the fetch command and dispatch the request. It will not, however, wait for the request to complete. Rather, it will continue on its way, output

The easiest way to do this is to use the Thread.Sleep method:


But I would recommend you to working with Tasks. This gives you an asynchronous process and the interface does not freeze. Then you could do something like this:

    public static async Task TaskMethod()
        Debug.WriteLine("Start Waiting");
        Task t = Task.Run(() => DoSomething() );

    private static void DoSomething()
        Console.WriteLine("Wake up !");

Python for Rookies: A First Course in Programming, A First Course in Programming Sarah Mount, James Shuttleworth, Russel Winder​. Threading the Code 11 Learning Outcomes At the end of this chapter you will be able User interface input devices have to process events every few seconds or have multiple processors and so can compute more than one thing at once  if you mean the HTML code to display after 5 seconds, set its CSS display to none and after 5 seconds set it to the previous value (an empty string, the browser figures out the rest). Hinz_Undkunz

If the code just has to wait and do nothing when the second card is shown, you could simply use the System.Threading.Thread.Sleep(1000); command. The '1000' you see means it will wait for 1 second. 2000 would be 2 seconds and so on. This command simply prevents the next step from happening for the given amount of time. I hope this helps!

Good luck!

Edit: I've just been told this does not work. Sorry!

Federal Register, You have reached the U.S. Government's telephone application processing system. telephone and would like to continue with the application process, press 1. For Rotary Callers After 5 seconds, the applicant will hear the following message please wait for the tone and speak clearly and distinctly.” 1. Citizenship: “Are  The default number of times that timeit will run your code is one million. If you were to run the above code with the default -n, then at 3 seconds per iteration, your terminal would hang for approximately 34 days! The timeit module has several other command line options that you can check out in its documentation.

Delay, Sleep, Pause, & Wait in JavaScript, Many programming languages have a sleep function that will delay a As one might expect, this code makes a request to the GitHub API to fetch my user data. to the console, then when the request returns a couple of hundred (or its cousin setInterval ) to keep JavaScript waiting until a condition is met. The .Wait method is available within Excel as a VBA function, as opposed to Sleep (see below). You can use it to specify that a macro is paused for a specific period of time. This example makes the macro pause for approximately 10 seconds: Application.Wait (Now + TimeValue ("0:00:10")) Or you can pause execution until a specific time e.g. this

The Scrum Field Guide: Practical Advice for Your First Year, Practical Advice for Your First Year Mitch Lacey. stuff going wrong bugs in stories 1823, 1842, and 1832 - fix them next sprint found bug but didn't have time to  The only thing we can ask is that they continue to contact us through the MiWAM account. They have a web notice page there where they can send a web notice if they have any questions. Just do it

Opportunity, A 105-mm howitzer of a field artillery unit of the 92nd Division is being fired at German "LET'S LOOK AT THE RECORD" (Continued from Page 13) When Prime Minister Churchill visited the 5th Army front and praised it as "one of the great After the shell was fired, the crew waited a few seconds, then yelled : "​How many  There is timeout command that waits for seconds. In case if millisecond sleep is needed, powershell's Start-Sleep can be used. To sleep 50ms in cmd: powershell Start-Sleep -m 50 – Pavel P Feb 22 '18 at 5:37. @Pavel: You can also misuse a ping to a non-existent host to sleep for milliseconds. – Joey Mar 1 '18 at 10:58.

  • Works like a charm! Thank you very much!
  • Task.Delay() not invented here. Also async method without await inside is a) not really asynchronous or b) indicates programming error
  • @ASh that's true.This was just an example of how asynchronous methods can be used for
  • This is an example how not to do things
  • @ASh That's true, but wouldn't it work if you put Thread.Sleep() right after the UI updates?
  • No, UI code is event-driven and should use a Timer rather than sleeping
  • @Ash ah, I didn't know that. Thank you for pointing me in the right direction.