csharp thread sleep

Code Example - csharp thread sleep

                
                        Thread.Sleep(2000); //in ms
                    
                
 

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);
                            
                        
 

sleep in csharp

                        
                                System.Threading.Thread.Sleep(50);
                            
                        
 

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 thread wait

                        
                                public class Form1 : Form
{
    int _count;

    void ButtonClick(object sender, EventArgs e)
    {
        ThreadWorker worker = new ThreadWorker();
        worker.ThreadDone += HandleThreadDone;

        Thread thread1 = new Thread(worker.Run);
        thread1.Start();

        _count = 1;
    }

    void HandleThreadDone(object sender, EventArgs e)
    {
        // You should get the idea this is just an example
        if (_count == 1)
        {
            ThreadWorker worker = new ThreadWorker();
            worker.ThreadDone += HandleThreadDone;

            Thread thread2 = new Thread(worker.Run);
            thread2.Start();

            _count++;
        }
    }

    class ThreadWorker
    {
        public event EventHandler ThreadDone;

        public void Run()
        {
            // Do a task

            if (ThreadDone != null)
                ThreadDone(this, EventArgs.Empty);
        }
    }
}
                            
                        
 

csharp sleep 1 second

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