Q:

C# program to pause a thread

0

C# program to pause a thread

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

/*
 * Program to Pause a Thread in C#
 */
using System;
using System.Threading;
class Program
{
    static void Main()
    {
        int loop=0;
        for (loop = 1; loop <= 4; loop++)
        {
            Console.WriteLine("Sleep Main thread for 1 Second");
            Thread.Sleep(1000);
        }

        Console.WriteLine("Main thread Finished");
    }
}

Output:

Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Sleep Main thread for 1 Second
Main thread Finished
Press any key to continue . . .

Explanation:

In the above program, we created a program class that contains a Main() method. In the Main() method, we created a for loop that will execute 4 times, here we used Thread.Sleep() method that will pause or sleep the Main thread for 1 second when Thread.Sleep() method gets called.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now