I am trying to use ThreadPool in C# Console application as shown below.
- static void Main(string[] args)
- {
- for (var i = 1; i<= 10; i++)
- {
- ThreadPool.QueueUserWorkItem(n =>
- {
- Console.WriteLine($"Start operation {n}");
- Thread.Sleep(1000);
- Console.WriteLine($"Operation {n} completed");
- }, i);
- }
- Console.ReadKey();
- }
But it is showing the below error:
The type or namespace name "QueueUserWorkItem" does not exist in the namespace "ThreadPool".
What I am doing wrong or which reference I need to add. I have already used the namespace system.Threading.
I am working on .Net framework version 4.6.