I know this may be strange, but I have a timer, and I have an event handler for the Elapsed event, which is written to the console, but when I launch the application, the timer starts correctly, the event fires correctly. However, the result is not displayed in the console, except that I press the button, which forced me to put two Console.ReadKey() so that the application does not end.
Here is the code in Program.cs :
static void Main(string[] args) { Timer timer = new Timer(100); timer.Elapsed += new ElapsedEventHandler(WriteOnConsole); timer.Start(); Console.ReadKey(); Console.ReadKey(); } static void WriteOnConsole(object source, ElapsedEventArgs e) { Console.WriteLine("ABCD"); }
Please let me know if I have not mentioned enough information.
source share