From the course: Threading in C#

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Thread pool demo

Thread pool demo - C# Tutorial

From the course: Threading in C#

Start my 1-month free trial

Thread pool demo

- [Instructor] Now, let's see how we can work with the thread pool. We're going to create another project. Let's call it ThreadPoolDemo. Again, we'll need to resolve the reference using System.Threading. There are a few different ways we can work with a thread pool. As mentioned earlier, we're actually going to use QueueUserWorkItem here. And this takes a WaitCallback, and if I had to pass the name of the method, it will take it as it is, but let me show you the verbose way of doing this where let's say we want to display the name of an employee. Well, let's say EmloyeeInfo, in this case. And also, want to pass in the object. And if that is employee, that should do it. So, let's create another class, which is class Employee. There are two properties. If you say prop and then hit Tab, you should be able to create a property. In this case, it's going to be Name and then you can do the same thing again, create another string property, and that could be the CompanyName. Very simple, it…

Contents