using System;
using System.Timers;
class Program
{
static void Main(string[] args)
{
Timer timer = new Timer(5000); // Set timer for 5 seconds
timer.Elapsed += (sender, e) => ExecuteFunction(timer);
timer.AutoReset = false; // Ensure it only runs once
timer.Start();
Console.WriteLine("Timer started. Waiting for 5 seconds...");
Console.ReadLine(); // Keep the application running
}
static void ExecuteFunction(Timer timer) {
timer.Stop();
Console.WriteLine("Function executed after 5 seconds!");
}
}
/*
run:
Timer started. Waiting for 5 seconds...
Function executed after 5 seconds!
*/