Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement