liveBook · Manning

SynchronizationContext.Post

As explained in C# Concurrency: Asynchronous and multithreaded programming

SynchronizationContext.Post asynchronously queues a callback for execution on the context's associated execution context without waiting for completion.

SynchronizationContext.Post asynchronously queues a callback for execution on the context’s associated thread or execution context. Unlike Send, it returns without waiting; await uses this nonblocking path when a synchronization context is present. section 11.2

Returning after await

A single-thread context can run an async operation, wait through Task.Delay, and process the continuation through Post so the before and after messages use the same thread.

How C# Concurrency: Asynchronous and multithreaded programming covers it

How deep it goes
Implements Post with a blocking work queue and contrasts it with Send, while deferring broader context members.
Examples
Uses a custom single-thread context, BlockingCollection, Task.Delay, and thread identifiers to demonstrate continuation placement.
What it assumes
Assumes familiarity with async/await and callbacks while demonstrating how SetSynchronizationContext and Current select the context.
What you can do after
Apply it via SynchronizationContext to enqueue callbacks without blocking and preserve a target thread for continuations.
How it connects
Connects SynchronizationContext with await, TaskScheduler, TaskScheduler.FromCurrentSynchronizationContext, and thread pools.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C# Concurrency: Asynchronous and multithreaded programming. The section links point to the parts of the book it draws on.