
Async/await & Patterns
async/await, Task, ValueTask, ConfigureAwait, cancellation tokens, parallel execution, deadlocks
1What is the main role of the 'await' keyword in an asynchronous method?
What is the main role of the 'await' keyword in an asynchronous method?
Câu trả lời
The await keyword suspends the execution of the asynchronous method until the Task completes, while freeing the calling thread to process other tasks. This avoids thread blocking and improves application scalability. Unlike Task.Wait() or Task.Result which block the thread, await enables efficient use of thread pool resources.
2Why should async void be avoided except for event handlers?
Why should async void be avoided except for event handlers?
Câu trả lời
Async void methods cannot be awaited and exceptions thrown inside cannot be caught by calling code, causing application crashes. Additionally, unit testing async void methods is impossible as there is no Task to await. Event handlers are the exception because they are called by the framework and cannot return Task.
3In which use case should ValueTask<T> be preferred over Task<T>?
In which use case should ValueTask<T> be preferred over Task<T>?
Câu trả lời
ValueTask is a value type that avoids heap allocation when the result is already available synchronously, such as in a cache. This reduces garbage collector pressure in high-performance scenarios. Task is always heap-allocated even if the result is synchronous. Use ValueTask only when performance gains are measurable, as incorrect usage can degrade performance.
What important restriction applies to ValueTask<T> compared to Task<T>?
What is the main purpose of ConfigureAwait(false) in a .NET library?
+23 câu hỏi phỏng vấn
Các chủ đề phỏng vấn .NET khác
C# Basics
LINQ & Delegates
C# Language Essentials
ASP.NET Core Fundamentals
ASP.NET Core Request Lifecycle
Configuration & Settings
Application Lifecycle
Dependency Injection
Entity Framework Core
Minimal APIs
Web API Development
Async in ASP.NET Core
Authentication & Authorization
HttpClient & Networking
JSON Serialization
Entity Framework Core Advanced
C# Advanced Features
Clean Architecture
Logging, Monitoring & Observability
Unit Testing & xUnit
Integration Testing
Docker & Containerization
NuGet Package Management
Memory Management & GC
Reactive Programming
.NET Design Patterns
Performance Optimization
Security & Best Practices
SignalR & Real-time
Microservices Architecture
Nắm vững .NET cho lần phỏng vấn tiếp theo
Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.
Bắt đầu miễn phí