Hola mundo


title: "¿Qué es async y await en C# y por qué deberías usarlos?" tags: [csharp, dotnet, asincronía, programación]

Cuando trabajamos con operaciones de red, archivos o bases de datos en C#, es común encontrar que algunas tareas toman tiempo. Si no las manejamos bien, bloqueamos el hilo principal y la experiencia del usuario se ve afectada.

Ahí es donde entran en juego async y await.


🚀 ¿Para qué sirven?

Permiten escribir código asíncrono que parece síncrono. En lugar de bloquear mientras algo termina (como una consulta a base de datos), el hilo continúa con otras tareas y “retoma” cuando se obtiene el resultado.


📦 Ejemplo práctico

Supongamos que quieres leer datos de una API:

public async Task<string> GetDataFromApiAsync(string url)
{
    using var client = new HttpClient();
    var response = await client.GetStringAsync(url);
    return response;
}
0
Subscribe to my newsletter

Read articles from Eduardo David Santiago Carrillo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Eduardo David Santiago Carrillo
Eduardo David Santiago Carrillo

I'm a .NET developer with a master's degree in information security and a strong focus on artificial intelligence. I'm passionate about building secure and intelligent web solutions by integrating technologies like OpenAI, Claude, DeepSeek, and LLaMA, both in the cloud and on local environments. I enjoy sharing knowledge with the tech community, writing about technology, and learning every day. My goal is to use code to solve real-world problems and help build a more efficient and secure future.