C Sharp Thread Sleep

C# Thread Sleep

To suspend the current thread for a specified time in milliseconds to give the chance to the other threads to start execution, the Sleep() method is used in C#.

Example:

using System;  
using System.Threading;  
public class Example  
{  
    public void thrd1()  
    {  
        for (char i = 'a'; i < 'g'; i++)  
        {  
            Console.WriteLine(i);  
            Thread.Sleep(100);  
        }  
    }  
}  
public class thrd2  
{  
    public static void Main()  
    {  
        Example thrd = new Example();  
        Thread x = new Thread(new ThreadStart(thrd.thrd1));  
        Thread y = new Thread(new ThreadStart(thrd.thrd1));  
        x.Start();  
        y.Start();  
    }  
}

Output:

Explanation:

In the above example, we are displaying the use and behavior of the Sleep() method in C#.

Please follow and like us:
Content Protection by DMCA.com