locked
variable as interval in timer control RRS feed

  • Question

  • I need to use time control in my windows form application.

    Also need to set and change the timer interval dynamically whlie programme is running. ie,  Today timer interval may be 60 minutes, tommarrow  70 minutes.

    Dragging timer controller to the form doesn't help as it only allow me to set the timer interval to a specific value.

    Appriciate help.

     

    Tuesday, March 30, 2010 7:45 AM

Answers

  • Thanks Amal & Mattia and all

    Your answer solved by problem.

    • Marked as answer by liurong luo Thursday, April 1, 2010 11:27 AM
    Tuesday, March 30, 2010 12:46 PM

All replies

  • static System.Timers.Timer myTimer = new System.Timers.Timer();
            static void Main(string[] args)
            {
                
                myTimer.Interval = 1000 * 60 * 15; //1000millisecond = 1 sec
                myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
                myTimer.Enabled = true;
                
                Console.ReadLine();
            }
    
            static void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                //Do the work
    
                //If Some condition change the timer interval
                myTimer.Stop();
                myTimer.Interval = newIntervalValue;
                myTimer.Start();
            }

    Make a note of the static fields, its because I wrote this in a console application. Change it as you wish.

     


    Thanks,
    A.m.a.L
    Dot Net Goodies
    Don't hate the hacker, hate the code
    Tuesday, March 30, 2010 7:53 AM
  • Thanks Amal & Mattia and all

    Your answer solved by problem.

    • Marked as answer by liurong luo Thursday, April 1, 2010 11:27 AM
    Tuesday, March 30, 2010 12:46 PM