[Gtk-sharp-list] Timer, possible bug?

Antonio Martínez Alvarez amartinez@atc.ugr.es
Sat, 22 May 2004 13:26:18 +0200


Julio Jiménez wrote:

> why this little program never stop when timer is running?
>
> using System;
> using System.Timers;
>
> public class Timer1
> {
>
>     public static void Main()
>     {
>         System.Timers.Timer aTimer = new System.Timers.Timer();
>         aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
>         // Set the Interval to 1 seconds.
>         aTimer.Interval=1000;
>     //aTimer.AutoReset = false;
>         //aTimer.Enabled=true;
>     aTimer.Start ();
>
>         Console.WriteLine("Testing Timer, interval = 1 second. Press 
> \'q\' to quit the sample.");
>         while(System.Console.Read()!='q');
>     }
>
>     // Specify what you want to happen when the Elapsed event is raised.
>     private static void OnTimedEvent(object source, ElapsedEventArgs e)
>     {
>         Console.WriteLine("Hello World!");
>     }
> }
>
>
> I think System.Console.Read() never ends

Hola Julio.
Just include a aTimer.Stop(); after your while loop and you'll see how 
your program ends when 'q' is pressed.

--
Antonio Martinez