using System;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main Thread ID = " + Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Is thread alive = "+Thread.CurrentThread.IsAlive);
Console.WriteLine("Is background thread = "+Thread.CurrentThread.IsBackground);
Console.WriteLine("Priority = " + Thread.CurrentThread.Priority);
Console.WriteLine("ThreadState = " + Thread.CurrentThread.ThreadState);
Console.WriteLine("CurrentCulture = " + Thread.CurrentThread.CurrentCulture);
Console.WriteLine("IsThreadPoolThread = " + Thread.CurrentThread.IsThreadPoolThread);
Console.ReadLine();
}
}
}
using System;
using System.Threading;
namespace ConsoleApplication1
{
class ThreadDemo
{
string name;
public int count;
public ThreadDemo(string n)
{
name = n;
}
public void run()
{
Console.WriteLine("\t Child Thread started");
do
{
Thread.Sleep(500);
Console.WriteLine("\t count for " + name + " is =>" + count);
count++;
} while (count < 6);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\n\n Main Thread started");
Console.WriteLine();
ThreadDemo obj = new ThreadDemo("Child Thread");
Thread t = new Thread(new ThreadStart(obj.run));
t.Start();
do
{
Console.Write("*");
Thread.Sleep(100);
} while (obj.count != 6);
Console.WriteLine();
Console.WriteLine("Main Thread terminated");
Console.ReadLine();
}
}
}
using System;
using System.Threading;
namespace ConsoleApplication1
{
class ThreadDemo
{
int count;
Thread t;
public ThreadDemo(string n)
{
ThreadStart ts = new ThreadStart(run);
t = new Thread(ts);
t.Name = n;
t.Start();
}
public void run()
{
do
{
Thread.Sleep(300);
Console.WriteLine("\n{0} THREAD started and count ={1} ", t.Name,count);
count++;
} while (count < 6);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main Thread started and ID= " + Thread.CurrentThread.ManagedThreadId);
Console.WriteLine();
ThreadDemo obj1 = new ThreadDemo("FIRST");
ThreadDemo obj2 = new ThreadDemo("SECOND");
Console.ReadLine();
}
}
}
using System;
using System.Threading;
namespace ConsoleApplication1
{
class ThreadDemo
{
public void Run(object ob)
{
Console.WriteLine("Current Thread ID ={0} ,{1}", Thread.CurrentThread.ManagedThreadId, ob);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main Thread started ");
Console.WriteLine();
ThreadDemo obj = new ThreadDemo();
Thread t = new Thread(new ParameterizedThreadStart(obj.Run));
t.Start("Welcome at TutorialRide");
Thread.Sleep(200);
Console.WriteLine("Main Thread terminated " );
Console.ReadLine();
}
}
}
using System;
using System.Threading;
class ThreadDemo
{
int count;
public Thread t;
public ThreadDemo(string name)
{
count = 0;
t = new Thread(this.Run);
t.Name = name;
t.Start();
}
void Run()
{
Console.WriteLine(t.Name + " started.");
do
{
Thread.Sleep(600);
Console.WriteLine(t.Name + ", count is " + count);
count++;
} while (count <=5);
Console.WriteLine(t.Name + " terminated.");
}
}
class Program
{
public static void Main()
{
Console.WriteLine("Main thread started.\n");
ThreadDemo obj1 = new ThreadDemo("Child Thread 1");
obj1.t.Join();
ThreadDemo obj2 = new ThreadDemo("Child Thread 2");
obj2.t.Join();
Console.WriteLine("Main thread terminated.");
Console.ReadLine();
}
}