using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace MyFirstConsoleApplication
{
class Program
{
static void Main(string[] args)
{
new Program();
for(int j=0;j<10;j++)
{
Console.WriteLine("Main Thread" + j.ToString());
Thread.Sleep(1000);
}
}
//When Start will called, the new thread will begin executing the ThreadStart delegate //passed
in the constructor. Once the thread is dead, it cannot be restarted with //another call to start.
public Program()
{
Thread thread = new Thread(new ThreadStart(WriteData));
thread.Start();
}
/// <summary>
/// WriteData is a function which will be executed by the thread
/// </summary>
protected static void WriteData()
{
string str;
for (int i = 0; i <= 10; i++)
{
str = "Secondary Thread" + i.ToString();
Thread.Sleep(1000);
Console.WriteLine(str);
}
}
}
}