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();
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nLlRhc2tzOwoKbmFtZXNwYWNlIFJlY2V0YXMuTXVsdGl0aHJlYWQuUjA0MDEKewogICAgcHVibGljIGNsYXNzIFVzb1Rhc2sKICAgIHsKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpIAogICAgICAgIHsKICAgICAgICAgICAgLy8gQ3JlYWNpw7NuIGRlIHVuIG9iamV0byBUYXNrIHF1ZSBlamVjdXRhIHVuIHByb2Nlc28gYXNpbmNyw7NuaWNvIAogICAgICAgICAgICAvLyBjb21vIHVuYSBleHByZXNpw7NuIGxhbWJkYToKICAgICAgICAgICAgVGFzayB0YXJlYSA9IFRhc2suUnVuICggKCkgPT4gCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgaW50IGNvbnRhZG9yQ2ljbG9zOwogICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgIGZvciAoY29udGFkb3JDaWNsb3MgPSAwOyBjb250YWRvckNpY2xvcyA8PSAxMDAwMDAwOyArK2NvbnRhZG9yQ2ljbG9zKQogICAgICAgICAgICAgICAgICAgIHt9CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIlxuTsO6bWVybyBkZSBjaWNsb3MgZWplY3V0YWRvczogezB9XG4iLCBjb250YWRvckNpY2xvcyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBFc3BlcmEgaGFzdGEgcXVlIGxhIHRhcmVhIGZpbmFsaWNlIHN1IGVqZWN1Y2nDs246CiAgICAgICAgICAgIHRhcmVhLldhaXQoKTsKICAgICAgICB9CiAgICB9Cn0=