csharp thread wait

Code Example - 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

                        
                                using System.Threading;

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

csharp thread sleep

                        
                                Thread.Sleep(2000); //in ms
                            
                        
 

import time csharp

                        
                                using system.Threading //Thread.sleep