How to use ThreadPool in c#?

c#

Solution

From the documentation for `Console.ReadKey()`:

The ReadKey method waits, that is, blocks on the thread issuing the ReadKey method, until a character or function key is pressed.

What it actually does is acquire a lock on `Console.InternalSyncObject`, which prevents further operations on the console.

The `Console.ReadLine()` method does not block the thread in this way. You can use it instead.

Reading this article I'm guessing you have .NET 4.5 installed?

Problem

When I run this code then nothing is shown on the console, but when I debug then it displays the output. Please explain why this happen? How I can get info when the Thread completes the task? ``` public class TestClass { static void Main() { ThreadPool.SetMaxThreads(5, 5); for (int x = 0; x < 10; x++) { ThreadPool.QueueUserWorkItem(new WaitCallback(printnum), x); } Console.ReadKey(); } public static void printnum(object n) { Console.WriteLine("Call " + n); for (int i = 0; i < 10; i++) { Console.WriteLine(i); } } } ```

Original source

Related problems