tags:

views:

17

answers:

3

I have following code in the form_Load function

System.Windows.Forms.Timer newtimer = new Timer();
newtimer.Tick += new EventHandler(refreshinfo);
newtimer.Start();
newtimer.Interval = 20000;

The "refreshinfo" function goes like this:

private void refreshinfo(object source,EventArgs e)
{
       // Some code here
}

The function "refreshinfo" is called after the 20 seconds. So far so good. Problem is that i want "refreshinfo" to be called on form_Load event also. So that i can get the desired results from "refreshinfo" when the user loads this form.

A: 

Why don't you just trigger the refreshinfo() function in the Form_Load function?

Christian W
+1  A: 
public void Form_Load(object sender, EventArgs e)
{
    // Invoke it after 20 seconds
    Timer newtimer = new Timer();
    newtimer.Tick += refreshinfo;
    newtimer.Interval = 20000;
    newtimer.Start();

    // Invoke it now
    refreshinfo(sender, e);
}
Timwi
Thanks bro... It just works fine now.
booota
A: 

Just run it in form_Load

Thread thrd = new Thread(() => { refreshinfo(null, null); });
thrd.Start();
Orsol