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
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Understanding threading2m 55s
-
(Locked)
Context switching7m 12s
-
(Locked)
Thread naming2m 33s
-
(Locked)
Shared resources2m 52s
-
(Locked)
Shared resources demo7m 35s
-
(Locked)
Threads vs. processes1m 1s
-
(Locked)
Local memory2m 50s
-
(Locked)
Thread pool2m 41s
-
(Locked)
Thread pool demo9m 49s
-
(Locked)
Other threading concepts3m 27s
-
(Locked)
Exception handling4m 37s
-
-
-
-