
Explore how concurrency enables doing several tasks at the same time to improve efficiency. See how parallelism uses multiple threads and asynchronous programming to serve more web requests concurrently.
explain parallel programming divides work and runs tasks simultaneously to save time. discover data and task parallelism, and how the task parallel library and plinq enable parallel processing of arrays.
Explore sequential programming and the basics of concurrency. Clarify how multi threading, parallelism, and multitasking relate, including when threading does not imply parallelism and how an operating system schedules threads.
Install Visual Studio and configure the desktop development workload to prepare for concurrency work with the wind farms framework. Use the community edition if needed and consider cross-platform options.
Explore how concurrency uses parallel and asynchronous programming to run tasks simultaneously, improve vertical scalability and user interface responsiveness, and distinguish CPU-bound from I/O-bound work.
Use async and await to implement asynchronous programming, freeing the current thread from waiting and preventing blocking, with applicability across various development environments and a simple application example.
Create a wind farms project in the net framework, drag a start button, add a loading gif, center the image, and demonstrate asynchronous programming.
Learn how asynchronous methods return Task or Task<T> to represent future operations and why await enables non-blocking execution. See why void is avoided except in event handlers.
Execute multiple tasks concurrently with Task.WhenAll to process many cards via an API. Use a thread-safe random generator to simulate approvals, measure performance with a stopwatch, and explore scalability issues.
Offload long-running work to a background thread with Task.Run to keep the UI responsive in a C# async program, using await and async methods to wait for results.
Limit concurrent tasks in C# by using SemaphoreSlim to throttle batched requests to a web API. The lecture demonstrates safe release on errors and practical batching for controlled parallelism.
Analyze credit card responses using Task.WhenAll to gather results, deserialize each response into a CardResponse with card and approve fields, identify rejected cards, and log outcomes to the console.
Learn how to report progress for multiple asynchronous tasks using IProgress, updating a progress bar and displaying percentages to users.
Learn how to cancel a custom loop by passing a cancellation token, detect cancellation inside the loop, and stop the operation with break or a TaskCanceledException.
Demonstrates cancelling with a timeout using a cancellation token and the cancel after method to automatically cancel a long running task after a set timespan, such as five seconds.
Explore creating finished tasks for unit testing by returning already completed, with an exception, or canceled tasks in synchronous methods with async signatures, using Task.FromResult, Task.FromException, and Task.FromCanceled.
Show how synchronization context preserves execution on the original UI thread after an await in UI frameworks, using await, async, and tasks.
Explore how ConfigureAwait(false) bypasses the synchronization context, letting continuations run on a different thread. Understand when capture context matters and why it has no effect on net core.
learn the only-one pattern in c# to run multiple asynchronous calls, return the first result, and cancel the rest with a cancellation token and task.whenany.
Master how to cancel non cancellable tasks in C# by using a task completion pattern and a with-cancellation extension, leveraging cancellation tokens and OperationCanceledException.
Explore how asynchronous programming avoids blocking the UI using Task and await, manage tasks with Task.WhenAll and Task.WhenAny. Learn progress reporting, cancellation tokens, and configuring awaits within a synchronization context.
Explore asynchronous streams in C#, returning sequences of dynamically generated values with async enumerable. Learn about the innumerable interface, the geo keyword, and how to cancel asynchronous streams.
Explore asynchronous streams in C# by using the async enumerable interface to iterate data without blocking the user interface, handling paginated web service results efficiently.
Explore two approaches to canceling asynchronous streams, including a break-based method and using a cancellation token with delays, cancellation handling, and resource disposal.
Learn to cancel asynchronous streams produced by IAsyncEnumerable by applying the enumerator cancellation attribute and using with cancellation to pass a cancellation token from the consumer.
Explore how to define asynchronous streams using yield, generate stream values one by one, and cancel asynchronous streams with a cancellation token in C#.
Explore antipatterns in asynchronous programming in C#, naming bad practices like deadlocks, void misuse, and improper cancellation, and emphasize proper async patterns, cancellation, and asynchronous streams.
Learn how blocking an async method with Task.Result on the UI thread creates a deadlock, and avoid it by using await or configuring await to bypass the synchronization context.
Avoid wrapping a synchronous method with an async counterpart; instead expose the synchronous method and let clients decide to use async when appropriate, to preserve scalability.
The lecture explains why Task.Factory.StartNew is risky in asynchronous programming, highlighting nested task results and showing that Task.Run offers simpler syntax and safer unwrapping with await.
Dispose cancellation token sources to free resources after timeouts and timers. Use finally or using patterns to auto dispose, whether as a field or inside a method.
Disposing streams in an asynchronous method can cause buffered data to flush synchronously, creating blocking. Use asynchronous disposal and PostAsync to flush the buffer without blocking.
Explore parallelism to speed up program processes. Review when not to use parallelism, atomic methods, race conditions, interlocks and locks, and parallel actions on collections.
Learn how Parallel.For executes iterations concurrently in C#, revealing that order is not guaranteed and that parallelism speeds up workloads when tasks can run independently.
Demonstrates parallelism in a CPU-bound matrix multiplication using a parallel for to divide work across threads, boosting processor utilization and speeding up computation.
Parallelism speeds up execution, but incurs setup costs, so measure performance to decide when parallelism pays off; use a mix of parallel and sequential code guided by data.
Learn to cancel parallel operations in C# by using a cancellation token, a cancellation source, and parallel options to stop long matrix multiplications.
Explore how to configure the maximum degree of parallelism in C#, control the number of concurrent threads, and measure its impact on execution time when multiplying matrices in parallel.
Discover atomic methods for safe data sharing in multithreaded C# apps, guaranteeing no intermediate state and consistent results. Achieve atomicity with locks and concurrent collections to avoid data corruption.
Ensure thread-safe methods by preventing data corruption when multiple threads access data. Use interlock or luks, immutable objects, and pure functions that return the same result for the same inputs.
Learn how Interlocked operations provide atomic updates across multiple threads, preventing race conditions when incrementing a shared value, by using atomic increment and add to ensure thread-safe results.
ThreadStatic creates a per-thread static field, giving each thread its own copy to avoid interference and safely host non-thread-safe classes, like a per-thread random generator seeded by RNGCryptoServiceProvider.
Learn how PLINQ enables parallel queries on collections with AsParallel, set the degree of parallelism, and use a cancellation token. Maintain original order with AsOrdered after parallel operations.
Learn how to perform aggregates in PLINQ, summing and averaging elements in parallel, and compare sequential versus parallel performance with custom aggregation for matrices.
Process matrix elements as soon as they are ready by using for all with a parallel query, displaying elements to the console as they become available.
Explore what not to do with parallelism, highlighting when little work doesn't justify it, the risks of race conditions from shared variables, and how to avoid over parallelization and deadlocks.
Race conditions occur when parallel code increments a variable in a multithreaded context, yielding unpredictable results. Use interlock to make increments atomic, with memory barriers and locks as alternatives.
Examine why the random class is not thread-safe in multithreaded environments and implement a safe pattern using ConcurrentDictionary with AddOrUpdate and a dedicated lock to synchronize random value generation.
Understand the dangers of using locks in large applications, avoid reusing objects across locks, and prevent deadlocks by using dedicated lock objects and keeping code inside locks simple.
Avoid parallelism for small tasks; when work is limited, overhead slows it below sequential performance. Use locks or interlocks to prevent race conditions and keep code inside the lock simple.
In this course you will learn how to use asynchronous programming and parallelism in C #.
We will look at both patterns and antipatterns of concurrency. That is, we will see what things we should do, but we will also see what things we should not do.
With asynchronous programming we can:
Run a set of I / O tasks at the same time
Prevent the UI of our applications from freezing
Scale up our ASP.NET and ASP.NET Core applications
Cancel tasks so that the user does not have to wait for their completion
Implement generic retry logic
Create asynchronous streams
With parallel programming we can:
Accelerate the execution of certain algorithms
Apply transformations to a set of images in parallel
Use synchronization mechanisms to avoid race conditions
Define the maximum degree of parallelism
Configure instances of a class by threads
Use LINQ in parallel
We'll also see:
Determinism vs Non-Determinism
Handling errors in asynchronous programming
Using Task.WhenAll to wait for the execution of multiple tasks
Reporting progress of multiples tasks
Retry pattern for handling momentaneous errors
Understanding and consuming ValueTask
Using Asynchronous streams
What does it mean for an app to be deadlocked
We will learn all of this in this course!