Jb11281992 Jb11281992 - 1 month ago 4x
C# Question

Why is my timer not initiating in my Web Form project?

When I run the program, there is no console output. I have attempted a few other timer procedures and to no avail.

Code Snippet:

namespace WindowsFormsApplication1
static class Program
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
Application.Run(new Form1());

System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = 3000;
aTimer.Enabled = true;


private static void OnTimedEvent(object source, ElapsedEventArgs e)
Console.WriteLine("Hello World!");


Application.Run(new Form1()); is a blocking call. It basically just sits there until you close your application.


To check it out, put a break point on the entry to the Main() function, and debug-step through your application!