Answers for "c# sleep 1 second"

C#
14

c# Sleep

using System.Threading;

static void Main()
{
  //do stuff
  Thread.Sleep(5000) //will sleep for 5 sec
}
Posted by: Guest on March-02-2020
5

c# wait for seconds

using System;
using System.Threading;

class Example
{
    static void Main()
    {
        for (int i = 0; i < 5; i++)
        {
            Console.WriteLine("Sleep for 2 seconds.");
            Thread.Sleep(2000);
        }

        Console.WriteLine("Main thread exits.");
    }
}

/* This example produces the following output:

Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Sleep for 2 seconds.
Main thread exits.
 */
Posted by: Guest on March-23-2020
0

c# wait seconds

//wait 2 seconds
Thread.Sleep(2000);
Task.Delay(2000);

//Both are valid options but I would recommend Task.Delay() as you can still use your UI while waiting
Posted by: Guest on December-08-2020
4

c# thread sleep

Thread.Sleep(2000); //in ms
Posted by: Guest on June-05-2020

C# Answers by Framework

Browse Popular Code Answers by Language