
Explore how the CPU executes applications through threads, and how the thread scheduler assigns threads to the CPU using a time slice, enabling multithreading and asynchronous programming.
Create a console app in Visual Studio 2022 with .NET 8, declare and start a thread to print the current thread id, demonstrating parallel execution with main and secondary threads.
Use divide and conquer with threading to split a big task into chunks, process in parallel, and join results to compute the final sum.
Offload long running tasks to a worker thread to keep the main UI responsive, illustrating how asynchronous programming and multithreading enable non-blocking interfaces.
Enqueue requests on the main thread, monitor the queue on a thread, and process input on another thread to simulate a web server, noting race conditions with a normal queue.
Explore how multi-threading shares resources, causing race conditions, and learn synchronization techniques to safely increment a shared counter and prevent conflicts in concurrent C#/.NET tasks.
Explore the critical section and atomic operations in multi-threaded C#/.NET, showing how non-atomic access to a shared counter causes synchronization issues and how indivisible code prevents them.
Apply an exclusive lock to the critical section with lock(lockObject) { ... }, so only one thread runs the body at a time, making the operation effectively atomic.
Apply exclusive locks to a multi-threaded airplane seats booking system with a shared available-ticket counter, simulating a web server where B books and C cancels, highlighting synchronization.
Implement a thread-safe airplane seats booking system in C# that uses a lock to guard the critical section, manages available tickets, and supports booking and cancellation via input.
Learn how to use monitor to guard the critical section, implement timeouts with try enter, and provide user feedback when the system is busy, improving thread synchronization in C#.
Learn how to use a named global mutex to synchronize access to a shared resource across processes, protecting a critical section and avoiding race conditions with a using statement.
Explore reader-writer locks that let multiple readers access a shared resource concurrently while writers gain exclusive access, enabling thread synchronization and data integrity in multi-threaded applications like caches.
Explore how semaphores limit concurrent threads using semaphore slim, with initial and maximum counts, wait and release, to prevent overloading a web server and protect critical sections.
Explore the auto reset event as a binary signaling mechanism between a producer and multiple consumers, using wait one and set in a practical Visual Studio example.
Learn two-way signaling in a producer–consumer scenario using a shared queue and manual reset events to coordinate batching, signaling, and multi-threaded consumption.
Understand thread safety: code can be used by multiple threads concurrently without race conditions or data corruption, when shared resources like a queue are protected by locks, mutexes, or semaphores.
Learn to debug multi-threaded C# programs in Visual Studio using the threads window, parallel stacks, breakpoints, and the thread marker to inspect call stacks, thread IDs, and deadlocks.
Explore thread states in .NET from unstarted to running, wait, sleep, and stopped, observe state transitions in Visual Studio, and learn to use logging for debugging rather than synchronization.
Explore three thread waiting techniques in C#/.NET: Thread.Sleep, SpinWait, and SpinUntil, highlighting when to pause a thread, the impact on the CPU and scheduler, and how timeouts work.
Demonstrates canceling a long-running worker thread with a shared cancel flag and user input. Introduces cancellation tokens via Cancellationtokensource and token.IsCancellationRequested for future task-based scenarios.
Learn how thread pool reuse improves performance by avoiding new thread creation, with max and min thread settings, available and active threads, and queueing work items for execution.
Discover the basic syntax of using task, compare it with thread, and explore task.start, task.run, delegates, and asynchronous execution, including continuewith and exception handling.
Compare task and thread: a task is a promise to complete work in the future, using a thread pool; it returns values and enables async/await with exception handling and continuation.
Tasks run on the thread pool by default, enabling efficient concurrency; you don't need to manage pool size, so use task rather than raw threads.
Learn how to return a value from a Task in C# by using Task<TResult>, accessing the result property, and printing the value with console write line.
Learn to return results by converting a divide-and-conquer example from four threads to tasks for a 1–10 array. Practice using task and return values in C#/.NET.
Learn to convert a four-task divide-and-conquer pattern from threads to tasks, return integer results from Task<TResult>, and sum them with Task.Result or Task.Sum while understanding thread pool behavior.
Learn how to manage task continuation in C#/.NET using wait, wait all, and the result property. Compare blocking with Task.Result to awaiting, using practical examples with delay and http get.
Chain non-blocking tasks with ContinueWith in C#/.NET, get the first task's result, and parse JSON to print the first Pokemon's name and URL.
Explore continuation chains in c#/.net by chaining tasks with continue-with across multiple steps. Use unwrap to avoid task-of-task layers and extract pokemon details (name, weight, height) from json.
Learn how exceptions in tasks are hidden and surfaced as aggregate exceptions with inner exceptions. Use WhenAll, task status faulted, and await versus wait to handle asynchronous errors robustly.
Task synchronization mirrors thread synchronization; apply locks, mutexes, semaphores, and events to tasks. The video shows replacing thread with task in a semaphore example and maintaining thread-safe queue access.
Explore using cancellation tokens to cancel tasks, create a cancellation token source, pass tokens to Task.Run, and handle cancellation via throw if cancellation requested and timeout patterns.
Explore async and await in task-based asynchronous programming, convert blocking calls to non-blocking code, and manage continuations and synchronization context within async methods.
Learn the basic syntax of async and await in C#, including task and task<T> return types and continuations after await. See practical examples like task.delay and console app patterns.
Trace how async/await manages threads before and after awaits: initial code runs on the main thread, while continuations may run on a thread pool thread and reuse threads for efficiency.
Use the await keyword and async/await to convert continuation after returning values into readable, non-blocking code, enabling fetch of Pokemon list and details with weight and height.
Learn how async and await expose exceptions from parallel tasks, replacing hidden aggregate exceptions with the first inner exception, and understand how thread scheduling affects error handling.
Explore how the synchronization context governs thread affinity between the UI thread in Windows Forms and background tasks, and how await keeps continuations on the UI context.
Learn parallel loops in c# and .net, using parallel for and for each to divide and conquer data, with async/await context, locks for shared state, and invoke concepts.
Explore what happens behind the scenes of parallel loops in C#/.NET: data partitioning into chunks and using thread pool threads; parallel calls are blocking until completion.
Show how to use break to exit a parallel loop in C#/.NET, using the lowest break iteration and state.should exit current iteration to control execution, compare with stop and exceptions.
Explore how parallel loop results work in C#/.NET, examining the ParallelLoopResult type, isCompleted, lowestBreakIteration, and how break, stop, and exceptions affect completion status in parallel loops.
Learn cancellation in parallel loops using a cancellation token source and parallel options, trigger cancellation with user input, and understand the blocking behavior while handling aggregate and task canceled exceptions.
Explore thread local storage in parallel loops, using per-thread locals to accumulate sums, aggregate results, and reduce lock contention with TLS initialization and local aggregation.
Explore how parallel loops implement the producer–consumer pattern with a configurable buffer, showing default, auto, and fully buffered modes, and the differences between for each and for all.
Explains the difference between for each and for all, noting the producer–consumer pattern, buffering, and that for all avoids merging and can be faster when merging isn't needed.
Explore concurrent collections by using a concurrent queue to achieve thread-safe first-in, first-out behavior with try dequeue, avoiding manual locks in multi-threaded scenarios.
Learn how blocking collection wraps concurrent queues or stacks to enable a producer and consumer pattern with bounding and blocking. Use get consuming enumerable and complete adding to finish.
Welcome to “Master Multithreading and Asynchronous Programming in C# & .NET 8”! Learning multithreading and asynchronous programming is crucial for developing high-performance, responsive, and scalable applications. These skills enable efficient use of CPU resources, keeping applications responsive by offloading long-running tasks. They are essential for handling real-world scenarios like web servers and complex simulations, and they future-proof your skills for modern multi-core hardware. Mastering these techniques not only enhances problem-solving abilities but also opens up valuable career opportunities in the tech industry.
This comprehensive course is designed to equip you with the skills and knowledge needed to harness the full power of multithreading and asynchronous programming in C# and .NET. Whether you’re a seasoned developer looking to deepen your expertise or a newcomer eager to learn, this course has something for everyone.
Course Overview
In this course, you’ll
Explore the intricacies of CPU, threads, and thread schedulers in .NET, and learn the basic syntax to start a thread.
You’ll discover the benefits of threading, such as dividing and conquering tasks and offloading long-running processes. Through hands-on assignments, like creating a web server and an airplane seats booking system,
You’ll gain practical experience in thread synchronization, thread safety, and more. These are very important topics for multithreading / parallel programming.
We’ll delve into advanced topics like task-based asynchronous programming, async and await, parallel loops, and PLINQ in .NET.
You’ll also learn about concurrent collections and how to handle exceptions and cancellations in multithreaded environments.
By the end of this course, you’ll be well-versed in creating efficient, responsive, and robust applications using C# in .NET.
Why Choose This Course?
Comprehensive Curriculum: Covering everything from the basics to advanced concepts, this course ensures you have a thorough understanding of multithreading and asynchronous programming.
Hands-On Assignments: Practical assignments help you apply what you’ve learned and gain real-world experience.
Expertly Curated Content: Each module is carefully crafted to build upon the previous one, ensuring a seamless learning curve.
Flexible Learning: Access the course materials anytime, anywhere, and learn at your own pace.
Who Is This Course For?
Intermediate and experienced .NET / C# developers: Looking to enhance their skills in multithreading and asynchronous programming.
Students: Pursuing a degree in computer science or a related field.
Professionals: Working in industries where efficient and responsive applications are crucial.
Hobbyists: Interested in expanding their programming knowledge and tackling more complex projects.
Prerequisites
Intermediate knowledge of C# and .NET
Visual Studio 2022 or later installed
Have a desire to learn