myTimer.Stop() can't stop!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chua Wen Ching

    #1

    myTimer.Stop() can't stop!

    Hi there.

    I am displaying a string which will appear 1 char at a
    time. The problem is after it display the 1st string, it
    will keep on continue.

    When i uncomment the myTimer.stop(), it does not even run
    at all.. cannot see anything on the command prompt.

    Any help?

    using System;
    using System.Timers;

    namespace Handling_Events ___1_char_at_a_ time
    {
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
    static int counter = 0;
    static string displayString = "Hello World!";

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    //
    // TODO: Add code to start application here
    //
    Timer myTimer = new Timer(100);

    myTimer.Elapsed += new ElapsedEventHan dler(WriteChar) ;
    myTimer.Start() ;

    //myTimer.Stop();

    Console.ReadLin e();
    }

    static void WriteChar(objec t source, ElapsedEventArg s e)
    {
    Console.Write(d isplayString[counter++ %
    displayString.L ength]);

    }
    }
    }

    Any help?

    I am starting to learn events as well.

    Regards,
    Chua Wen Ching
  • Bruce Brown

    #2
    Re: myTimer.Stop() can't stop!

    Hi,

    Try using the System.Threadin g.Timer.

    Regards,

    - Bruce.


    "Chua Wen Ching" <cwc@cwc.com> wrote in message
    news:02fd01c354 05$debd8d80$a40 1280a@phx.gbl.. .[color=blue]
    > Hi there.
    >
    > I am displaying a string which will appear 1 char at a
    > time. The problem is after it display the 1st string, it
    > will keep on continue.
    >
    > When i uncomment the myTimer.stop(), it does not even run
    > at all.. cannot see anything on the command prompt.
    >
    > Any help?
    >
    > using System;
    > using System.Timers;
    >
    > namespace Handling_Events ___1_char_at_a_ time
    > {
    > /// <summary>
    > /// Summary description for Class1.
    > /// </summary>
    > class Class1
    > {
    > static int counter = 0;
    > static string displayString = "Hello World!";
    >
    > /// <summary>
    > /// The main entry point for the application.
    > /// </summary>
    > [STAThread]
    > static void Main(string[] args)
    > {
    > //
    > // TODO: Add code to start application here
    > //
    > Timer myTimer = new Timer(100);
    >
    > myTimer.Elapsed += new ElapsedEventHan dler(WriteChar) ;
    > myTimer.Start() ;
    >
    > //myTimer.Stop();
    >
    > Console.ReadLin e();
    > }
    >
    > static void WriteChar(objec t source, ElapsedEventArg s e)
    > {
    > Console.Write(d isplayString[counter++ %
    > displayString.L ength]);
    >
    > }
    > }
    > }
    >
    > Any help?
    >
    > I am starting to learn events as well.
    >
    > Regards,
    > Chua Wen Ching[/color]


    Comment

    Working...