Consider the following code :
namespace MyThreads
{
public class HisThread
{
public int Thread2(int start, int end, int[] arr)
{
int sum = 0;
// foreach (int i in arr)
for (int i = start; i <= end; i++)
{
sum += arr[i];
}
return sum;
}
}
public class MyThread
{
public void Thread1()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Hello world " + i);
Thread.Sleep(1);
}
}
}
public class Test
{
public static void Main()
{
int[] arr = new int[30];
for (int i = 0; i < 30; i++ )
{
arr[i] = i;
}
Console.WriteLine("Before start thread");
// thread 1 - without params
MyThread thr = new MyThread();
Thread tid1 = new Thread(new ThreadStart(thr.Thread1)); // this one is OK
tid1.Start();
// thread 2 - with params
HisThread thr2 = new HisThread();
Thread tid2 = new Thread(new ParameterizedThreadStart(thr2.Thread2));
}
}
}
The first thread compiles fine (with no arguments) but the second thread produces
Error 1 No overload for 'Thread2' matches delegate
Any idea how to fix that ?
Thanks