C# Program example to Sleep a thread



Example for sleep thread:-
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication2
{
    class mainthread
    {
        public static void ChildCall()
        {
            Console.WriteLine(“Child thread is starting”);
            int number;
            number = 2000;
            Console.WriteLine(“Child is sleeping for {0} second:”, number/1000);
            Thread.Sleep(number);
            Console.WriteLine(“Waking Up”);
            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            ThreadStart th = new ThreadStart(ChildCall);
            Console.WriteLine(“Requesting to Start”);
            Thread create = new Thread(th);
            Console.WriteLine(“Starting the Thread”);
            create.Start();
            Console.ReadLine();
        }
    }
}

Add Comment