I have created delegates with the same signature like function passed for Thread class job:
public delegate void myDelegateForThread();
static void Main(string[] args)
{
myDelegateForThread del = thrFunc;
Thread t = new Thread( del);
t.Start();
for (int i = 0; i < 10000; i++) { Console.WriteLine("Main thread " +i); }
Console.ReadLine();
}
public static void thrFunc()
{
for (int i = 0; i < 10000; i++) { Console.WriteLine("Secondary thread " + i); }
}
But compiler is not happy I don't pass ThreadStart
for Thread
constructor. I know how to solve problem in this case, but my question is can I do typecast for delegates if they have the same signature?