Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 25, 2014 04:25
Show Gist options
  • Save Fhernd/14a4402a6da02385baf3 to your computer and use it in GitHub Desktop.
Save Fhernd/14a4402a6da02385baf3 to your computer and use it in GitHub Desktop.
Demostración de uso del constructor Timer(TimerCallback, Object, TimeSpan, TimeSpan) en C#.
using System;
using System.Threading;
namespace Recetas.Cap04
{
public sealed class EjecucionTareaProgramada
{
public static void Main()
{
// Crea intervalo de tiempo de 10 segundos:
TimeSpan tiempoEspera = new TimeSpan (0, 0, 10);
// Crea un temporizador que se iniciará 10 segundos
// después de creada una instancia de Timer. Y
// sólo se ejecutará una vez:
new Timer (
delegate (object obj)
{
Console.WriteLine ("\nEl temporizador se inició a las {0}",
DateTime.Now.ToString ("HH:mm:ss.ffff"));
},
null, tiempoEspera, new TimeSpan(-1)
);
Console.Write ("\nA espera de finalización del temporizador.");
Console.WriteLine (" Presione Enter para finalizar.");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment