stop timer before refreshing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Elliot

    stop timer before refreshing

    My program use a timer to 'refresh' a method "a" every several seconds,

    private void a(object sender, EventArgs eArgs)
    {
    Timer T1 = new Timer();
    T1.Interval = 100000;
    T1.Start();
    T1.Tick += new EventHandler(b) ;

    Timer T2 = new Timer();
    T2.Interval = 100000;
    T2.Start();
    T2.Tick += new EventHandler(c) ;
    }

    Inside "a", there are two timers.
    My question is how can I stop timers T1 & T2 before refreshing "a" for a new
    time?

    Thanks for any idea.

  • Ignacio Machin ( .NET/ C# MVP )

    #2
    Re: stop timer before refreshing

    On Jun 30, 3:54 pm, "Elliot" <elliot_barc... @hotmail.co.ukw rote:
    My program use a timer to 'refresh' a method "a" every several seconds,
    >
            private void a(object sender, EventArgs eArgs)
            {
                                    Timer T1 = new Timer();
                                    T1.Interval = 100000;
                                    T1.Start();
                                    T1.Tick += new EventHandler(b) ;
    >
                                    Timer T2 = new Timer();
                                    T2.Interval = 100000;
                                    T2.Start();
                                    T2.Tick += new EventHandler(c) ;
            }
    >
    Inside "a", there are two timers.
    My question is how can I stop timers T1 & T2 before refreshing "a" for a new
    time?
    >
    Thanks for any idea.
    You need to have a reference to them, in other words declare them at
    the class level, not inside the method
    but what are you trying to do? Those many timers are really necesary?

    Comment

    • Elliot

      #3
      Re: stop timer before refreshing

      It works. Thanks, Ignacio.


      "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin @gmail.comwrote in
      message
      news:d2a5bf81-7d35-438b-a981-a5baf98619a4@a7 0g2000hsh.googl egroups.com...
      On Jun 30, 3:54 pm, "Elliot" <elliot_barc... @hotmail.co.ukw rote:
      >My program use a timer to 'refresh' a method "a" every several seconds,
      >>
      >private void a(object sender, EventArgs eArgs)
      >{
      >Timer T1 = new Timer();
      >T1.Interval = 100000;
      >T1.Start();
      >T1.Tick += new EventHandler(b) ;
      >>
      >Timer T2 = new Timer();
      >T2.Interval = 100000;
      >T2.Start();
      >T2.Tick += new EventHandler(c) ;
      >}
      >>
      >Inside "a", there are two timers.
      >My question is how can I stop timers T1 & T2 before refreshing "a" for a
      >new
      >time?
      >>
      >Thanks for any idea.
      >
      You need to have a reference to them, in other words declare them at
      the class level, not inside the method
      but what are you trying to do? Those many timers are really necesary?

      Comment

      Working...