What you will learn in C# Concurrency: Asynchronous and multithreaded programming
Asynchronous and multithreaded programming
Chapter by chapter
Chapter 14: Generating collections asynchronously/await foreach and IAsyncEnumerable
What you learn in chapter 14 →Concepts explained in this book
- async/awaitAsync/await is a C# language feature for expressing asynchronous operations with synchronous-looking control flow.
- asynchronous programmingAsynchronous programming is an execution model in which a program can initiate an operation and continue other work without synchronously waiting for that operation to finish.
- multithreadingThe execution of multiple threads within a program, either concurrently through interleaving or simultaneously on multiple processor cores.
- Task.ContinueWithA .NET Task method that creates a continuation to run after the task completes, fails, or is canceled.
- ConfigureAwaitConfigureAwait(false) configures an await continuation not to capture the current SynchronizationContext or TaskScheduler.
- Task.RunTask.Run is a .NET method that schedules a delegate or asynchronous function for execution on a thread-pool thread and returns a Task representing its completion.
- TaskCompletionSource<T>TaskCompletionSource<T> is a generic .NET class that provides a Task<T> whose completion and result can be controlled explicitly by application code.
- IAsyncEnumerable<T>IAsyncEnumerable<T> is a .NET generic interface representing an object that asynchronously provides an enumerator for traversing a sequence of values.
- BlockingCollection<T>BlockingCollection<T> is a .NET generic collection type that supports thread-safe production and consumption of items, including blocking consumption until items become available.
- concurrent collectionA concurrent collection is a collection designed to support correct access by multiple threads without requiring callers to provide all synchronization.
- CancellationTokenA CancellationToken is a .NET value that communicates a request to cancel an asynchronous or otherwise cancellable operation.
- exceptionAn exception is an object representing an abnormal condition that interrupts normal program execution and can be thrown or propagated.
- SynchronizationContextSynchronizationContext is a .NET abstraction for posting or sending callbacks to a particular execution context, such as a UI thread.
- blockingA blocking operation is an operation that prevents its thread from making progress while waiting for external data, another thread, or another condition.
- deadlockA deadlock is a program state in which two or more execution flows remain stuck because each is waiting for progress that cannot occur.
- await foreachAwait foreach is a C# language feature that asynchronously iterates over elements produced by an asynchronous enumerable.
- Task.ExceptionTask.Exception is the .NET Task property that exposes an exception associated with a faulted asynchronous operation.
- arrayAn array is a contiguous, indexed block of memory whose elements are stored sequentially.
- ConcurrentQueue<T>ConcurrentQueue<T> is a .NET thread-safe generic FIFO collection that supports concurrent item insertion and removal.
- compilerA compiler is a program that translates source code into another representation, such as executable code or an intermediate form.
- ConcurrentDictionary<TKey,TValue>ConcurrentDictionary<TKey,TValue> is a .NET thread-safe generic key-value collection that supports concurrent access and atomic conditional updates.
- cachingA cache is a storage layer that retains previously obtained values so they can be returned more quickly on later requests.
- CancellationTokenSourceCancellationTokenSource is a .NET object that creates and controls cancellation tokens, including by requesting cancellation.
- yieldYield return is a C# language feature that produces an iterator element and suspends execution until the iterator advances again.
- TaskCompletionSource<T>.TrySetResultTrySetResult is a TaskCompletionSource method that attempts to complete its associated task successfully and reports whether the attempt succeeded.
- memory access reorderingMemory access reordering is the rearrangement, elimination, or combination of memory operations while preserving the results observable under the applicable execution model.
- blocked stateA blocked state is a thread state in which the operating system prevents a thread from receiving CPU time until the condition it is waiting for is satisfied.
- CompleteAddingA BlockingCollection<T> method that marks the collection as unable to accept additional items after existing items have been consumed.
- GetConsumingEnumerableA BlockingCollection<T> method that returns an enumerable which removes items as they are iterated and waits when the collection is empty until production ends or an item becomes available.
- ImmutableInterlockedImmutableInterlocked is a .NET API that provides atomic operations for updating references to immutable collections and related immutable values.
- AcceptAsyncAcceptAsync is an asynchronous socket operation that returns a Task<Socket> completing when an incoming connection arrives.
- asynchronous serverAn asynchronous server handles client operations without synchronously blocking a thread while waiting for external activity.
- SendAsyncSendAsync is an asynchronous socket operation that transfers data and represents completion with a task containing the accepted byte count.
- thread-per-requestA one-thread-per-request server assigns a dedicated thread to handle each client request.
- immutable stackAn immutable stack is a last-in, first-out collection whose push and pop operations produce new stack versions without changing existing versions.
- persistent mapImmutableDictionary<TKey,TValue> is a .NET generic dictionary whose contents cannot be changed after creation and whose modification methods return modified copies.
- TryAddTryAdd is a ConcurrentDictionary method that conditionally inserts a key-value pair and returns false when the key already exists.
- parallelismParallel execution is the simultaneous execution of multiple operations by separate processing resources.
- Task<T>.ResultA Task<T> property that provides the task's computed result and synchronously waits if the task has not completed, propagating cancellation or failure as an exception.
- context switchingA context switch is the act of saving one thread's execution state and loading another thread's state so the processor can run it.
- ConcurrentStack<T>ConcurrentStack<T> is a .NET thread-safe generic LIFO collection that supports concurrent item insertion and removal.
- synchronizationSynchronization is the coordination of concurrent operations so that they occur in a controlled sequential order rather than simultaneously.
- thread safetyThread safety is the property that data and operations remain correct when accessed or modified concurrently by multiple threads.
- race conditionA race condition is a concurrent-execution defect in which program results depend on uncontrollable timing or interleaving between execution flows.
- work queue patternThe work queue pattern coordinates producers and background consumers by placing work items in a queue for later processing.
- starvationStarvation is a concurrency condition in which a thread is prevented from making progress because another thread retains a required resource for an excessive time.
- frozen collectionA frozen collection is a collection whose contents are fixed after construction and optimized for read-only access.
- ParallelParallel is a .NET class that provides static methods for executing delegates and loop iterations concurrently.
- IAsyncEnumerator<T>IAsyncEnumerator<T> is a .NET generic interface that asynchronously advances through a sequence and exposes its current value.
- acquire semanticsAcquire semantics are memory-ordering guarantees that prevent reads from being moved earlier than a synchronization operation.
- memory barrierA memory barrier is a synchronization operation that prevents reads and writes from being reordered across it.
- acquire-release semanticsRelease semantics are memory-ordering guarantees that prevent writes from being moved later than a synchronization operation.
- ConcurrentBag<T>A .NET thread-safe unordered collection optimized for concurrent additions and removals, especially when the same thread performs both operations.
- Thread.StartThread.Start is a .NET Thread method that begins execution of the thread and can optionally supply an object argument to its delegate.
- TaskCreationOptions.RunContinuationsAsynchronouslyRunContinuationsAsynchronously is a .NET task-creation option that causes task continuations to run asynchronously rather than inline during task completion.
- awaiterAn awaiter is an object that provides the compiler-facing mechanism for determining completion and retrieving the result of an awaitable operation.
- partial updateA partial update is an inconsistency that occurs when concurrent access observes some data values from before an update and some values from after it.
- SynchronizationContext.PostSynchronizationContext.Post asynchronously queues a callback for execution on the context's associated execution context without waiting for completion.
- Parallel.ForEachParallel.ForEach is a .NET method that executes an operation for the elements of a sequence potentially in parallel and completes after all iterations finish.
- Parallel.ForEachAsyncParallel.ForEachAsync is a .NET method that asynchronously executes an operation for the elements of a sequence and returns a task representing completion of all iterations.
- ConcurrentDictionary<TKey,TValue>.TryUpdateTryUpdate is a ConcurrentDictionary method that replaces a value only when its current value matches an expected value.
- GetOrAddGetOrAdd is an ImmutableInterlocked operation that returns an existing value or adds and returns a value for a missing key in an immutable dictionary.
- TaskCanceledExceptionTaskCanceledException is a .NET exception indicating that an operation represented by a Task was canceled.
- async void methodAn async void method is a C# asynchronous method with a void return type that cannot expose a Task representing its completion or failure.
- at-least-once deliveryAt-least-once delivery is a message-delivery guarantee that permits duplicates but ensures a message is delivered one or more times.
- at-most-once deliveryAt-most-once delivery is a message-delivery guarantee that delivers a message zero or one time and does not intentionally retry it after loss.
- poison messageA poison message is a message that repeatedly fails processing and may prevent normal queue consumption unless it is isolated or discarded.
- IEnumerable<T>IEnumerable<T> is a .NET generic interface representing an object that can provide an enumerator for traversing a sequence of values.
- IEnumerator<T>IEnumerator<T> is a .NET generic interface that exposes the current value of a sequence and advances enumeration to the next value.
- iterator methodA C# method associated with yield return that produces a sequence through deferred, resumable execution.
- Task.WaitA .NET Task method that synchronously waits for the task to complete and propagates unsuccessful completion as an exception.
- try-catch statementA try-catch block is a C# exception-handling construct that catches exceptions raised by code in its try region.
- Control.BeginInvokeBeginInvoke is a user-interface framework method that asynchronously schedules a delegate for execution on the thread associated with a control or component.
- AggregateExceptionAggregateException is a .NET exception type that represents one or more exceptions produced by an operation or group of operations.
- GetAsyncEnumeratorGetAsyncEnumerator is a method that obtains an asynchronous enumerator for traversing an asynchronous sequence, optionally accepting a cancellation token.
- TaskSchedulerTaskScheduler is a .NET abstraction that controls how Task continuations and other task work are scheduled for execution.
- TrySetExceptionTaskCompletionSource.TrySetException attempts to fault the associated non-generic Task and associate one or more exceptions with it.
- Channel<T>Channel<T> is a .NET asynchronous producer-consumer communication type for exchanging values between writers and readers.
- WithCancellationWithCancellation is a .NET extension method that associates a cancellation token with an IAsyncEnumerable<T> for asynchronous iteration.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
