Created
June 19, 2014 02:08
-
-
Save Fhernd/c0a5e2e0d20f90e5658a to your computer and use it in GitHub Desktop.
Pausa de dos threads que se ejecutan paralelamente. 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.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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment