using System;
using System.Threading;
namespace Articulos.Cap04
{
public sealed class MetodoAnonimoDelegadoThreadStart
{
public static void Main()
{
Thread thread = new Thread (
delegate()
{
for (int i = 0; i < 5; ++i)
{
Console.WriteLine (i.ToString());
// Pausa este thread por 0.5s:
Thread.Sleep (500);
}
}
);
// Inicia la ejecución del Thread:
thread.Start();
Console.WriteLine ("El método Main ha finalizado su ejecución.");
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIEFydGljdWxvcy5DYXAwNAp7CiAgICBwdWJsaWMgc2VhbGVkIGNsYXNzIE1ldG9kb0Fub25pbW9EZWxlZ2Fkb1RocmVhZFN0YXJ0CiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgVGhyZWFkIHRocmVhZCA9IG5ldyBUaHJlYWQgKAogICAgICAgICAgICAgICAgZGVsZWdhdGUoKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgKytpKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKGkuVG9TdHJpbmcoKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vIFBhdXNhIGVzdGUgdGhyZWFkIHBvciAwLjVzOgogICAgICAgICAgICAgICAgICAgICAgICBUaHJlYWQuU2xlZXAgKDUwMCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwogICAgICAgICAgICAKICAgICAgICAgICAgLy8gSW5pY2lhIGxhIGVqZWN1Y2nDs24gZGVsIFRocmVhZDoKICAgICAgICAgICAgdGhyZWFkLlN0YXJ0KCk7CiAgICAgICAgICAgIAogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIkVsIG3DqXRvZG8gTWFpbiBoYSBmaW5hbGl6YWRvIHN1IGVqZWN1Y2nDs24uIik7CiAgICAgICAgfQogICAgfQp9