I want to run a method in a thread pool. While build the following code it gives an error
No overload for 'method' matches delegate 'System.Threading.WaitCallback'.
I know where the error happens, but I don't know why:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Thread_Pool
{
class Program
{
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(PrintNumbers));
// PrintNumbers();
}
static void PrintNumbers()
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);
Thread.Sleep(3000);
}
}
}
}
When the above code is rewritten as the following, it works fine.
static void PrintNumbers(object Stateinfo)
Why does this happen? Instead of using object may I use another type (like int, float)?