Advertisement
Fhernd

UsoThread.cs

Sep 18th, 2014
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Receta.Multithreading.Cap01
  5. {
  6.     public sealed class UsoThread
  7.     {
  8.         public static void Main()
  9.         {
  10.             Thread thread = new Thread (new ThreadStart (ImprimirY));
  11.             thread.Start();
  12.        
  13.             // Esta sección se ejecuta en paralelo con la salida
  14.             // generada por el método encapsulado por el delegado
  15.             // ThreadStart en el nuevo thread `thread`:
  16.             for (int i = 0; i < 1000; ++i)
  17.             {
  18.                 Console.Write ("X");
  19.             }
  20.            
  21.             Console.WriteLine();
  22.         }
  23.        
  24.         // Se ejecuta de manera simultánea con la salida
  25.         // generada por la sección de `Main`:
  26.         public static void ImprimirY()
  27.         {
  28.             for (int i = 0; i < 1000; ++i)
  29.             {
  30.                 Console.Write ("Y");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement