Creating a background timer to run asynchronously

    // Create a 30 min timer 
    timer = new System.Timers.Timer(1800000);

    // Hook up the Elapsed event for the timer.
    timer.Elapsed += OnTimedEvent;

    timer.Enabled = true;


...

private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
    // do stuff
}

with the usual caveats of: timer won’t be hugely accurate and might need to GC.KeepAlive(timer)

See also: Why does a System.Timers.Timer survive GC but not System.Threading.Timer?

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)