Caffeinated Coder
Book an appointment
Lesson 18 · Advanced .NET

Tasks and threads

A thread is a path through your code that the operating system runs on a CPU core. Threads are costly, so .NET keeps a thread pool: a few worker threads that take jobs from a queue. Follow a program that splits 1 to 100 into two halves: Task.Run queues each half and returns a Task<int> at once, two workers add them up in parallel on two cores, and await Task.WhenAll collects 1275 and 3775 so the program prints 5050.

14 min10 steps5 questionsBeginner
Fig 18 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.