
Async in ASP.NET Core
async/await in controllers, CancellationToken, streaming responses, timeouts, async filters, IAsyncEnumerable
1Why use async/await in ASP.NET Core controller actions?
Why use async/await in ASP.NET Core controller actions?
Antwort
Using async/await in controllers frees thread pool threads during I/O operations (database, external APIs). This improves server scalability by allowing the thread to process other requests while waiting. Without async, the thread remains blocked and consumes resources unnecessarily, limiting the number of concurrent requests.
2What happens if a controller action returns Task<IActionResult> without using async/await?
What happens if a controller action returns Task<IActionResult> without using async/await?
Antwort
Returning Task<IActionResult> without async/await works if you directly return an existing Task (return dbContext.SaveChangesAsync();). However, without the async keyword, you cannot use await in the method body. Most of the time, using async allows awaiting multiple async operations and handling errors with try/catch.
3What is the difference between ToList() and ToListAsync() in a controller action?
What is the difference between ToList() and ToListAsync() in a controller action?
Antwort
ToList() is synchronous and blocks the thread during the database query, limiting scalability. ToListAsync() is asynchronous and frees the thread during I/O operations, allowing the server to process other requests. Always use ToListAsync() in controllers to maximize supported concurrent requests.
What is the role of CancellationToken in controller actions?
How to obtain the CancellationToken in an ASP.NET Core controller action?
+17 Interview-Fragen
Weitere .NET-Interviewthemen
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
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
Async/await & Patterns
.NET Design Patterns
Performance Optimization
Security & Best Practices
SignalR & Real-time
Microservices Architecture
Meistere .NET für dein nächstes Interview
Zugang zu allen Fragen, Flashcards, technischen Tests, Code-Review-Übungen und Interview-Simulatoren.
Kostenlos starten