csharp wait seconds

Code Example - csharp wait seconds

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

//Both are valid options but Task.Delay() can be used with the async keyword
                    
                
 

csharp Sleep

                        
                                using System.Threading;

static void Main()
{
  //do stuff
  Thread.Sleep(5000) //will sleep for 5 sec
}
                            
                        
 

how to wait in csharp

                        
                                System.Threading.Thread.Sleep(Milliseconds);
                            
                        
 

csharp thread sleep

                        
                                Thread.Sleep(2000); //in ms
                            
                        
 

sleep in csharp

                        
                                System.Threading.Thread.Sleep(50);
                            
                        
 

wait csharp

                        
                                void Start()
{
    StartCoroutine(waiter());
}

IEnumerator waiter()
{
    //Rotate 90 deg
    transform.Rotate(new Vector3(90, 0, 0), Space.World);

    //Wait for 4 seconds
    yield return new WaitForSeconds(4);

    //Rotate 40 deg
    transform.Rotate(new Vector3(40, 0, 0), Space.World);

    //Wait for 2 seconds
    yield return new WaitForSeconds(2);

    //Rotate 20 deg
    transform.Rotate(new Vector3(20, 0, 0), Space.World);
}
                            
                        
 

csharp sleep 1 second

                        
                                using System.Threading;
Thread.Sleep(1000);