1. What is Async Programming?
Async means:
Do not block the thread
Let long tasks run in background
Free thread to serve other requests
.NET Core = High-performance, non-blocking, scalable framework.
Async is the core reason ASP.NET Core handles 10x more users.
2. Why We Use Async in ASP.NET Core?
2.1. To avoid blocking while doing I/O
Ex: database calls, web API calls, file handling.
2.2. To increase scalability
Same server handles more users.
2. 3. To keep application responsive
UI never freezes.
3. How Async Works Internally (Simple)
Sync Flow
Thread → Starts work → Waits → Returns result.
Async Flow
Thread → Starts work → Releases thread → Work continues in background → Returns.
4. Async Keywords
| Keyword | Meaning |
|---|---|
| async | Marks a method as asynchronous |
| await | Waits for the async task without blocking |
| Task | Represents an async operation (no return) |
| Task<T> | Async operation with return type |
| ValueTask | Lightweight task |
5. Basic Syntax
Async Method
public async Task<int> AddAsync(int a, int b)
{
await Task.Delay(1000); // example of async work
return a + b;
}
Calling Async Method
int result = await AddAsync(10, 20);
6. Real-Time Example 1: Database Call (EF Core)
Service Class
public class CustomerService
{
private readonly AppDbContext _context;
public CustomerService(AppDbContext context)
{
_context = context;
}
public async Task<List<Customer>> GetCustomersAsync()
{
return await _context.Customers.ToListAsync();
}
}
Controller
[HttpGet]
public async Task<IActionResult> GetAllCustomers()
{
var customers = await _customerService.GetCustomersAsync();
return Ok(customers);
}
ToListAsync() does not block any thread.
Server handles 1000 users smoothly.
7. Real-Time Example 2: SQL Query (ADO.NET) Async
public async Task<DataTable> GetOfflineOrdersAsync()
{
using (SqlConnection con = new SqlConnection(_connectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Orders", con))
{
await con.OpenAsync();
using (SqlDataReader dr = await cmd.ExecuteReaderAsync())
{
DataTable dt = new DataTable();
dt.Load(dr);
return dt;
}
}
}
8. Real-Time Example 3: Async API Call (HttpClient)
public async Task<string> CallApiAsync()
{
HttpClient client = new HttpClient();
string response = await client.GetStringAsync("https://example.com/api/data");
return response;
}

Join the conversation! Your thoughts help the community grow.