Top community members
All Wiki Articles Create Wiki Article

Many years me and my friends we were volunteers on my university doing programming classes for young people.

I got main conclusion: Young people are awesome, especially students, because they always bring new and fresh ideas :)
* I loved to do it but my time is limited

  I decided to create something that will help millions of students

Now I am here

co-founder

C#/.NET - sleep thread

0 contributions
10 points

To pause thread in C#/.NET Thread.Sleep method can be used.

using System;
using System.Threading;

namespace Test
{
	class Program
	{
		static void Main(string[] args)
		{
			Thread thread = new Thread(() =>
			{
				Console.WriteLine("My thread: step 1");
				Thread.Sleep(1000);
				Console.WriteLine("My thread: step 2");
				Thread.Sleep(1000);
				Console.WriteLine("My thread: step 3");
			});

			thread.Start();

			Console.WriteLine("Main thread: step 1");
			Thread.Sleep(1000);
			Console.WriteLine("Main thread: step 2");
			Thread.Sleep(1000);
			Console.WriteLine("Main thread: step 3");
		}
	}
}

Output:

Main thread: step 1
My thread: step 1
Main thread: step 2
My thread: step 2
Main thread: step 3
My thread: step 3
Note: Thread.Sleep sleeps thread in which method has been called for some milliseconds.

References:

  1. Thread.Sleep Method - Microsoft Docs
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more