Created
July 24, 2014 15:33
-
-
Save Fhernd/12c80e2f4ac011f2dad9 to your computer and use it in GitHub Desktop.
Uso del delegado ParameterizedThreadStart y el método Start(Object).
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.Cap01.R0108 | |
{ | |
public sealed class UsoDelegadoParameterizedThreadStart | |
{ | |
public static void Main() | |
{ | |
// Creación de una nueva instancia de `Thread`. | |
// Al constructor le pasamos una instancia del delegado | |
// ParameterizedThreadStart. Este último encapsula al | |
// método Tarea1: | |
Thread threadNuevo = new Thread ( | |
new ParameterizedThreadStart (Tarea1) | |
); | |
// Aquí utilizamos la versión sobrecargad del método | |
// Start que recibe como argumento una instancia de | |
// `Object`: | |
threadNuevo.Start (7); | |
// Creación de una instancia de UsoDelegadoParameterizedThreadStart: | |
UsoDelegadoParameterizedThreadStart obj = new | |
UsoDelegadoParameterizedThreadStart(); | |
// Creamos otro thread: | |
threadNuevo = new Thread (obj.Tarea2); | |
// invocamos de nuevo al método Start sobre | |
// el nuevo thread: | |
threadNuevo.Start ("Blog xCSw"); | |
} | |
// Método estático: | |
public static void Tarea1(object datos) | |
{ | |
Console.WriteLine ("\nInicio ejecución método estático sobre un nuevo thread."); | |
Console.WriteLine ("Dato pasado como argumento: `{0}`.", datos); | |
} | |
// Método de instancia: | |
public void Tarea2(object datos) | |
{ | |
Console.WriteLine ("\nInicio ejecución método de instancia sobre un nuevo thread."); | |
Console.WriteLine ("Dato pasado como argumento: `{0}`.", datos); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment