What is the difference between concurrency and parallelism?
Concurrency means multiple operations can make progress during overlapping periods of time. They do not necessarily execute at exactly the same instant.
C# interview questions covering advanced async, parallelism & threading.
Open a question for the full answer, code and interview guidance.
Concurrency means multiple operations can make progress during overlapping periods of time. They do not necessarily execute at exactly the same instant.
I/O-bound work spends most of its time waiting for external resources such as databases, files, HTTP services, or network operations. async/await is normally the appropriate approach because the thread does not need to remain blocked while waiting.
ConfigureAwait controls whether an await should attempt to continue on the captured synchronization context.
ValueTask<T> is an awaitable value type that can represent either an already available result or an asynchronous operation.
IAsyncEnumerable<T> represents an asynchronous stream of values. Instead of waiting for an entire result set before processing begins, values can be produced and consumed asynchronously over time.
The .NET thread pool maintains reusable worker threads for executing short-lived work. Tasks, timers, asynchronous continuations, and many framework operations use thread-pool infrastructure.
Thread-pool starvation occurs when available worker threads are occupied or blocked faster than the runtime can make threads available for new work.
Parallel.ForEach executes loop iterations potentially in parallel using multiple threads. It is designed mainly for CPU-bound work where iterations are independent.
Parallel.ForEachAsync is an asynchronous parallel loop available in modern .NET. It allows each iteration to await asynchronous work while controlling the degree of parallelism.
Common mistakes include blocking on tasks with .Result or .Wait(), using async void for methods other than event handlers, forgetting to await tasks, starting excessive concurrent operations, and ignoring cancellation.