You are on page 1of 2

1.

using System;
using System.Threading;
namespace ConsoleAppTask
{
class Threading1
{
public static void ThreadCount()
{
int count = 0;
for(count=0;count<10;count++)
{
Thread.Sleep(3000);
Console.WriteLine("Count:" +count+" "+ DateTime.Now);
}
Console.WriteLine("Thread Ends");
}
static void Main(string[] args)
{
ThreadStart th = new ThreadStart(ThreadCount);
Console.WriteLine("Thread Starts");
Thread child = new Thread(th);
child.Start();
Console.ReadLine();
}
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------
2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleAppTask
{
class Threading2
{
public enum PriorityThread
{
India,America,Russia
}
static public void Main()
{

// Creating and initializing threads


Thread T1 = new Thread(work);
Thread T2 = new Thread(work);
Thread T3 = new Thread(work);

// Set the priority of threads


T2.Priority = ThreadPriority.Highest;
T3.Priority = ThreadPriority.BelowNormal;
T1.Start();
T2.Start();
T3.Start();

// Display the priority of threads


Console.WriteLine("The 1st priority thread is: {0}",
PriorityThread.India);

Console.WriteLine("The 2nd priority thread is: {0}",


PriorityThread.America);

Console.WriteLine("The 3rd priority of thread is: {0}",


PriorityThread.Russia);
Console.ReadLine();
}

public static void work()


{

// Sleep for 1 second


Thread.Sleep(1000);
}
}
}

You might also like