Created
June 18, 2014 18:09
-
-
Save Fhernd/5de9ba70539dc6599a0e to your computer and use it in GitHub Desktop.
Demostración de ejecución simultánea de dos métodos. 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 Receta.Multithreading.Cap01 | |
{ | |
public sealed class UsoThread | |
{ | |
public static void Main() | |
{ | |
Thread thread = new Thread (new ThreadStart (ImprimirY)); | |
thread.Start(); | |
// Esta sección se ejecuta en paralelo con la salida | |
// generada por el método encapsulado por el delegado | |
// ThreadStart en el nuevo thread `thread`: | |
for (int i = 0; i < 1000; ++i) | |
{ | |
Console.Write ("X"); | |
} | |
Console.WriteLine(); | |
} | |
// Se ejecuta de manera simultánea con la salida | |
// generada por la sección de `Main`: | |
public static void ImprimirY() | |
{ | |
for (int i = 0; i < 1000; ++i) | |
{ | |
Console.Write ("Y"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment