Created
June 19, 2014 02:39
-
-
Save Fhernd/4e96478d7524010f962a to your computer and use it in GitHub Desktop.
Demuestra la creación un método que introduce un retardo por cada iteración del ciclo for. Y otro método que se ejecuta sin declarar ningún tipo de retraso. 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; | |
namespace Recetas.Multithreading.Cap01 | |
{ | |
public sealed class ImpresionNumerosConRetraso | |
{ | |
// 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()); | |
} | |
} | |
// La salida del generada por cada iteración del | |
// ciclo for no genera ningún retraso: | |
public static void ImprimirNumerosSinRetraso() | |
{ | |
Console.WriteLine ("Inicio ejecución..."); | |
for (int i = 0; i < 10; ++i) | |
{ | |
Console.WriteLine (i.ToString()); | |
} | |
} | |
public static void Main() | |
{ | |
Thread thread = new Thread (ImprimirNumerosConRetraso); | |
thread.Start(); | |
ImprimirNumerosSinRetraso(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment