using System;
using System.Threading;
namespace Recetas.Multithreading.Cap01
{
internal sealed class ImpresorNumeros
{
// Imprime los números del 0 al 9 introduciendo
// un retraso de 2 segundos por cada iteración
// del ciclo for:
private static void ImprimirNumerosConRetraso()
{
Console.WriteLine ("Inicio ejecución...");
for (int i = 0; i < 10; ++i)
{
// Retraso (pausa) de dos (2) segundos:
Thread.Sleep (TimeSpan.FromSeconds (2));
Console.WriteLine (i.ToString());
}
}
public static void Main()
{
Console.WriteLine ("\nIniciando la aplicación...");
Thread threadNuevo = new Thread (ImprimirNumerosConRetraso);
// Inicio del thread:
threadNuevo.Start();
// Ponemos en espera el thread Main hasta que
// el thread threadNuevo termine:
threadNuevo.Join();
Console.WriteLine ("\nThread Main terminó.\n");
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuTXVsdGl0aHJlYWRpbmcuQ2FwMDEKewogICAgaW50ZXJuYWwgc2VhbGVkIGNsYXNzIEltcHJlc29yTnVtZXJvcwogICAgewogICAgICAgIC8vIEltcHJpbWUgbG9zIG7Dum1lcm9zIGRlbCAwIGFsIDkgaW50cm9kdWNpZW5kbyAKICAgICAgICAvLyB1biByZXRyYXNvIGRlIDIgc2VndW5kb3MgcG9yIGNhZGEgaXRlcmFjacOzbiAKICAgICAgICAvLyBkZWwgY2ljbG8gZm9yOgogICAgICAgIHByaXZhdGUgc3RhdGljIHZvaWQgSW1wcmltaXJOdW1lcm9zQ29uUmV0cmFzbygpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIkluaWNpbyBlamVjdWNpw7NuLi4uIik7CiAgICAgICAgICAgIAogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDEwOyArK2kpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIC8vIFJldHJhc28gKHBhdXNhKSBkZSBkb3MgKDIpIHNlZ3VuZG9zOgogICAgICAgICAgICAgICAgVGhyZWFkLlNsZWVwIChUaW1lU3Bhbi5Gcm9tU2Vjb25kcyAoMikpOwogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKGkuVG9TdHJpbmcoKSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJcbkluaWNpYW5kbyBsYSBhcGxpY2FjacOzbi4uLiIpOwogICAgICAgICAgICAKICAgICAgICAgICAgVGhyZWFkIHRocmVhZE51ZXZvID0gbmV3IFRocmVhZCAoSW1wcmltaXJOdW1lcm9zQ29uUmV0cmFzbyk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBJbmljaW8gZGVsIHRocmVhZDoKICAgICAgICAgICAgdGhyZWFkTnVldm8uU3RhcnQoKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIFBvbmVtb3MgZW4gZXNwZXJhIGVsIHRocmVhZCBNYWluIGhhc3RhIHF1ZSAKICAgICAgICAgICAgLy8gZWwgdGhyZWFkIHRocmVhZE51ZXZvIHRlcm1pbmU6CiAgICAgICAgICAgIHRocmVhZE51ZXZvLkpvaW4oKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiXG5UaHJlYWQgTWFpbiB0ZXJtaW7Dsy5cbiIpOwogICAgICAgIH0KICAgIH0KfQ==