• Featured post

C# Async ops

El nucleo de la programacion asincrona son los objetos Task y Task<T>. Son compatibles con las palabras clave async y await.

Primero hay que reconocer si el codigo se usa para trabajos enlazados a I/O o si son CPU intensivos.

  • Si el codigo “espera” algo como una BBDD o una response de un servidor, es codigo I/O. En este caso hay que usar async y await pero SIN usar Task.Run
  • Si el codigo realiza un calculo costoso, es CPU intensivo. Use async y await y genere otro subproceso con Task.run

Async / Await (Operaciones I/O)

La palabra clave importante aqui es await. Lo que hace es suspender la ejecucion del metodo actual y devolver el control hasta que está lista para seguir.

public Task Main()
{
	string contenido = await LeerPaginaWebAsync("http://example.com");
}

public async Task<string> LeerPaginaWebAsync(string url)
{
	using (HttpClient client = new HttpClient())
	{
		return await client.GetStringAsync(url);
	}
}

Read More

Personal Blog

personal-blog-old-image

Which problem does it solve?

Since the start of my programming career I’ve been writing little notes and programming how-to’s in Markdown. This way I don’t need to relearn the same thing twice and I don’t need to find the solution to an obscure problem twice.

After some time, that collection really grew and I needed a new way to be able to index, access and search all my information faster.

Technology Stack

You’re inside.