0
0
C Sharp (C#)programming~5 mins

Async and await keywords in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the async keyword do in C#?
The async keyword marks a method as asynchronous, allowing it to run operations without blocking the main thread. It enables the use of await inside the method.
Click to reveal answer
beginner
What is the purpose of the await keyword?
await pauses the execution of an async method until the awaited task completes, without blocking the thread. It helps write asynchronous code that looks like synchronous code.
Click to reveal answer
intermediate
Can an async method return void?
Yes, but only for event handlers. Normally, async methods return Task or Task<T> to allow callers to await them and handle exceptions.
Click to reveal answer
intermediate
What happens if you forget to use await inside an async method?
The method will run synchronously until it hits an awaited task. If you don't use await, the method may complete early and not wait for asynchronous operations, causing bugs.
Click to reveal answer
beginner
Why is using async and await better than blocking calls?
They keep the app responsive by not blocking threads. This is like waiting for a friend without stopping everything else you do, improving performance and user experience.
Click to reveal answer
What keyword do you use to mark a method as asynchronous in C#?
Athread
Bawait
Ctask
Dasync
What does the await keyword do?
ABlocks the thread until the task finishes
BPauses the async method without blocking the thread
CStarts a new thread
DCancels a running task
Which return type is common for async methods?
ATask or Task&lt;T&gt;
Bint
Cstring
Dvoid
What happens if you call an async method but do not use await?
AThe method runs synchronously and waits
BThe program crashes
CThe method runs asynchronously but caller does not wait
DThe method is ignored
Why should you avoid blocking calls in UI applications?
AThey freeze the UI and make it unresponsive
BThey keep the UI responsive
CThey improve performance
DThey use less memory
Explain how async and await work together in C# to keep applications responsive.
Think about waiting for a task without stopping everything else.
You got /4 concepts.
    Describe the common return types of async methods and why they are important.
    Consider how the caller knows when the async work is done.
    You got /5 concepts.