Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

C#/.NET - create thread

0 contributions
5 points

To run new thread in C#/.NET Thread class can be used.

using System;
using System.Threading;

namespace Test
{
	class Program
	{
		static void Main(string[] args)
		{
			Thread thread = new Thread(() =>
			{
				for (int i = 1; i <= 5; ++i)
				{
					Console.WriteLine("Iteration: " + i);
					Thread.Sleep(1000);
				}
			});

			thread.Start();
		}
	}
}

Output:

Iteration: 1
Iteration: 2
Iteration: 3
Iteration: 4
Iteration: 5

Where:

  • Thread class - creates new thread object
  • Thread.Start method - runs created thread
  • Thread.Sleep method - sleeps thread execution for 1 second (1000 milliseconds)

References

  1. Thread Class - 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