Jb11281992 Jb11281992 -4 years ago 128
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!");

Answer Source

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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download