Created
March 25, 2016 15:52
-
-
Save Fhernd/133aa2dbd9167fe574c7 to your computer and use it in GitHub Desktop.
Demostración de uso de la clase Task en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace Recetas.Multithread.R0401 | |
{ | |
public class UsoTask | |
{ | |
public static void Main() | |
{ | |
// Creación de un objeto Task que ejecuta un proceso asincrónico | |
// como una expresión lambda: | |
Task tarea = Task.Run ( () => | |
{ | |
int contadorCiclos; | |
for (contadorCiclos = 0; contadorCiclos <= 1000000; ++contadorCiclos) | |
{} | |
Console.WriteLine ("\nNúmero de ciclos ejecutados: {0}\n", contadorCiclos); | |
} | |
); | |
// Espera hasta que la tarea finalice su ejecución: | |
tarea.Wait(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment