Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Threading;
- namespace Recetas.Multithreading.Cap01
- {
- public sealed class PrecisionThreadSleep
- {
- public static void Main()
- {
- // Empieza cronometrar el tiempo transcurrido a partir
- // del inicio del Thread asociado con Main:
- Stopwatch sw = Stopwatch.StartNew();
- // Pausa el Thread 0 segundos:
- Thread.Sleep (0);
- // Detiene el crónometro:
- sw.Stop();
- Console.WriteLine (sw.ElapsedMilliseconds);
- Console.WriteLine (DateTime.Now.ToLongTimeString());
- // Inicia de nuevo el cronómetro:
- sw = Stopwatch.StartNew();
- // Detiene el Thread por 5000 ms (5s):
- Thread.Sleep (5000);
- sw.Stop();
- Console.WriteLine (sw.ElapsedMilliseconds);
- Console.WriteLine (DateTime.Now.ToLongTimeString());
- // Una vez más iniciamos el cronómetro:
- sw = Stopwatch.StartNew();
- Thread.Sleep(1000);
- sw.Stop();
- Console.WriteLine (sw.ElapsedMilliseconds);
- Console.WriteLine (DateTime.Now.ToLongTimeString());
- Console.WriteLine ();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement