I have created a console test application which creates, an object & calls 2 functions on 2 separate threads. One thread prints numbers form 1- 20 the other in the reverse order.
The problem is while debugging the 1st worker thread does not get fired till I don't stop debugging the main thread (i.e. I press f5). Any answers?
class Program
{
static void Main(string[] args)
{
DisplayData dd = new DisplayData();
ThreadStart ts1 = new ThreadStart(dd.DisplayNumber);
Thread t1 = new Thread(ts1);
t1.Name = "Display Numbers";
ThreadStart ts2 = new ThreadStart(dd.ReverseNumbers);
Thread t2 = new Thread(ts2);
t2.Name = "Reverse Numbers";
t1.Start(); //Keep 1st break point at this location. Then press F10.
t2.Start(); //Keep break point at this location permanently
}
public class DisplayData
{
public void DisplayNumber()
{
int length = 20;
Console.WriteLine("\nNumbers in correct order.\n");
for (int i = 0; i < length; i++)
{
Console.WriteLine("DN: The value of i is: " + (i+1) + " " + Thread.CurrentThread.ManagedThreadId + " " + Thread.CurrentThread.Name);
//Thread.Sleep(1000);
}
}
public void ReverseNumbers()
{
int length = 20;
Console.WriteLine("\nNumbers in reverse order.\n");
for (int i = 0; i < length; i++)
{
Console.WriteLine("RN: The value of i is: " + (length - i) + " " + Thread.CurrentThread.ManagedThreadId + " " + Thread.CurrentThread.Name);
//Thread.Sleep(1000);
}
}