Advertisement
Fhernd

UsoBasicoThreadAbort2.cs

Jun 26th, 2014
1,780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Recetas.Multithreading.Cap01
  5. {
  6.     internal sealed class UsoBasicoThreadAbort
  7.     {
  8.         public static void Main()
  9.         {
  10.             Thread nuevoThread = new Thread(
  11.                 delegate()
  12.                 {
  13.                     Console.WriteLine ("\nDentro del thread `nuevoThread`...");
  14.                     // Ciclo infinito...
  15.                     // Será interrumpido por nuevoThread.Abort() en
  16.                     // el thread Main:
  17.                     while(true);
  18.                 }
  19.             );
  20.            
  21.             nuevoThread.Start();
  22.            
  23.             // Permite que el thread nuevoThread se ejecute
  24.             // durante 2 segundos:
  25.             Thread.Sleep (2000);
  26.            
  27.             // Aborta la ejecución del thread:
  28.             nuevoThread.Abort();
  29.            
  30.             Console.WriteLine ();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement