Link to home
Start Free TrialLog in
Avatar of mike_pro
mike_pro

asked on

Repeat a function every 2 mins

I have a function getColors() which i need to run every 2 mins (this function just queries a website for some data and updates some images). How can you get a function to do this?
Avatar of tculler
tculler
Flag of United States of America image

Well, I don't know of a built-in function, but you can use a timer, instead. I'll give a sample code snippet.

        class TwoMinuteTimer : System.Timers.Timer
        {
            /// <summary>Initializes a new timer that fires its Elapsed event ever 120 seconds.</summary>
            /// <param name="myElapsedEvent">The method to call ever 2 minutes.</param>
            public TwoMinuteTimer(ElapsedEventHandler myElapsedEvent)
                : base(120000.0) // 120,000 milliseconds, aka 120 seconds/2 minutes for the interval.
            {
                this.Start();
                this.Elapsed += myElapsedEvent;
            }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tculler
tculler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial