What is asynchronous programming in C#?
Asynchronous programming allows a thread to avoid blocking while waiting for an operation such as database access, HTTP communication, file I/O, or another asynchronous resource.
C# interview questions covering async/await, tasks & multithreading.
Open a question for the full answer, code and interview guidance.
Asynchronous programming allows a thread to avoid blocking while waiting for an operation such as database access, HTTP communication, file I/O, or another asynchronous resource.
The async modifier allows a method to use await and normally indicates that the method returns Task, Task<T>, ValueTask, or ValueTask<T>. The await operator asynchronously waits for an awaitable operation to complete.
Task represents an asynchronous operation that does not produce a result value. Task<T> represents an asynchronous operation that eventually produces a value of type T.
Synchronous code normally waits for each operation to complete before continuing. If a thread performs blocking I/O, that thread remains occupied while waiting.
Task.WhenAll returns a task that completes when all supplied tasks have completed. It is useful when independent asynchronous operations can run concurrently and all results are required.
A thread is an execution path within a process. Multiple threads can execute work concurrently.
A process is an operating-system container for a running application. It has its own virtual address space and resources.
A race condition occurs when multiple execution paths access shared mutable state concurrently and the program's result depends on timing or execution order.
The lock statement provides mutual exclusion around a critical section. Only one thread can execute code protected by the same lock object at a time.
CancellationToken provides a cooperative mechanism for requesting cancellation of asynchronous or long-running operations.