Creating And Starting Taks C# with Example



Creating And Starting Taks C# with Example

 using System;
using System.Threading;
using System.Threading.Tasks;

namespace CSharpMultiThreading
{
	class Program
	{
		static void PrintHelloTask()
		{
			Thread.Sleep(50);
			Console.WriteLine("PrintHelloTask executing for Secondary Thread#{0} on TickCount: {1}", Thread.CurrentThread.ManagedThreadId, Environment.TickCount);
		}

		static void Main()
		{
			Console.WriteLine("Main Thread ID: {0}", Thread.CurrentThread.ManagedThreadId);
			
			// Create and Start ten new threads.
			for (int i = 0; i < 10; i++)
			{
				new Task(PrintHelloTask).Start();
			}
			Console.ReadLine();
		}
	}
} 

0 Comment's

Comment Form

Submit Comment