Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 19, 2014 02:08
Show Gist options
  • Save Fhernd/c0a5e2e0d20f90e5658a to your computer and use it in GitHub Desktop.
Save Fhernd/c0a5e2e0d20f90e5658a to your computer and use it in GitHub Desktop.
Pausa de dos threads que se ejecutan paralelamente. En C#.
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