Problem : you are using invalid quotes “
to enclose the String in Console.WriteLine()
method as below:
Console.WriteLine(“ThreadProc: {0}”, i);
and here
Console.WriteLine(“Main thread: Do some work.”);
Solution : you need to use proper double quotes "
to enclose the String as below:
Console.WriteLine("ThreadProc: {0}", i);
and also
Console.WriteLine("Main thread: Do some work.");
Complete Code:
using System;
using System.Threading;
namespace Chapter1
{
public static class Program
{
public static void ThreadMethod()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("ThreadProc: {0}", i);
Thread.Sleep(0);
}
}
public static void Main()
{
Thread t = new Thread(new ThreadStart(ThreadMethod));
t.Start();
for (int i = 0; i < 4; i++)
{
Console.WriteLine("Main thread: Do some work.");
Thread.Sleep(0);
}
t.Join();
}
}
}