Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Repeat a function every 2 mins

Posted on 2009-05-12
4
Medium Priority
?
1,046 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:mike_pro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:tculler
ID: 24364265
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

0
 
LVL 9

Accepted Solution

by:
tculler earned 1000 total points
ID: 24364284
Sorry, hit the tab + enter by accident.

You would do the following to start retreiving your colors:

TwoMinuteTimer timer = new TwoMinuteTimer(MyEventHandler);

void MyEventHandler(System.Timers.ElapsedEventArgs elapArgs)
{
     // Get your color here. I recommend loading it into a buffer of some sort, like a List<Color>, or a Queue<Color>
}

Hope I helped, feel free to ask any other questions.
0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 1000 total points
ID: 24364287
You can add a timer to your form.

timer1 = new System.Timers.Timer();
timer1.Elapsed += new System.Timers.ElapsedEventHandler( timer1_Elapsed );

timer1.Interval = 120000;
timer1.Enabled = true;


private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
   ... do something
}
            
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question