using System;
using System.Threading;
namespace Recetas.Multithreading.Cap02
{
public sealed class UsoSleepConThread
{
public static void Main()
{
Thread thread = new Thread (new ThreadStart (EscribirMundo));
thread.Start();
// En cada iteración, se realiza una pausa de 1 segundo:
for (int i = 0; i <= 10; ++i)
{
Console.WriteLine ("Hola");
Thread.Sleep (1000);
}
Console.WriteLine ();
}
// Método relacionado con el delegado ThreadStart para
// invocación de forma simultánea con Thread. Mientras
// se ejecuta se pausa cada 500ms (0.5s):
private static void EscribirMundo ()
{
for (int i = 0; i <= 10; ++i)
{
Console.WriteLine ("Mundo");
Thread.Sleep (500);
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuTXVsdGl0aHJlYWRpbmcuQ2FwMDIKewogICAgcHVibGljIHNlYWxlZCBjbGFzcyBVc29TbGVlcENvblRocmVhZAogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIFRocmVhZCB0aHJlYWQgPSBuZXcgVGhyZWFkIChuZXcgVGhyZWFkU3RhcnQgKEVzY3JpYmlyTXVuZG8pKTsKICAgICAgICAgICAgdGhyZWFkLlN0YXJ0KCk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBFbiBjYWRhIGl0ZXJhY2nDs24sIHNlIHJlYWxpemEgdW5hIHBhdXNhIGRlIDEgc2VndW5kbzoKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPD0gMTA7ICsraSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJIb2xhIik7CiAgICAgICAgICAgICAgICBUaHJlYWQuU2xlZXAgKDEwMDApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICAvLyBNw6l0b2RvIHJlbGFjaW9uYWRvIGNvbiBlbCBkZWxlZ2FkbyBUaHJlYWRTdGFydCBwYXJhIAogICAgICAgIC8vIGludm9jYWNpw7NuIGRlIGZvcm1hIHNpbXVsdMOhbmVhIGNvbiBUaHJlYWQuIE1pZW50cmFzIAogICAgICAgIC8vIHNlIGVqZWN1dGEgc2UgcGF1c2EgY2FkYSA1MDBtcyAoMC41cyk6CiAgICAgICAgcHJpdmF0ZSBzdGF0aWMgdm9pZCBFc2NyaWJpck11bmRvICgpCiAgICAgICAgewogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8PSAxMDsgKytpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIk11bmRvIik7CiAgICAgICAgICAgICAgICBUaHJlYWQuU2xlZXAgKDUwMCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0=