Hey All,

Threading may not be the answer to this, but here's my current situation.

I have a form that I want updated about every 5 seconds. I couldn't figure out how to do this, so I just did a refresh on a button click on that form. However, in order to do this, I have to create an entire new instance of that form, close the old one, and then show the new one.

private void buttonRefresh_Click(object sender, System.EventArgs e) 
{            
Status stat = new Status(...);            
this.Close();            
stat.Show();        
}

So while this works, there are probably better solutions, but i basically just want it to update every 5 seconds.

Thanks,
-Mario

Member Avatar for iamthwee

Out of interest what exactly does your program do?

The form that i need to refresh displays a bunch of information read in and displays it in different labels/textboxes on the on the form.

Member Avatar for iamthwee

Are you saying you just need to clear text field then update them with new information?

If that's the case can't you just do.

TextBox1.Text = "";

yes i can do that, but how do i automate that process with a timer?

im trying to avoid the button press to refresh.

Member Avatar for iamthwee

I'm assuming it would be the same as always.

Every five seconds run code
  TextBox1.Text = "":
  TextBox2.Text = "";
  TextBoxn.Text = "";

yada yada yada...?

which brings me back to my original question:

I don't know how to use a timer like that. How to set up a method or block of code to be ran every 5 seconds. It would obviously have to be on a separate thread, which i also do not understand how to do :)

Member Avatar for iamthwee

Maybe I'm missing something but isn't there a time elapsed function in the timer class.

Then you can keep track of the time. When it hits every five seconds ( i.e perform a modulus five = 0 or something similar) then run the code to reset the text fields? I'm not sure how useful the below links are. I looked at them briefly. I don't think you need a time controlling function on a separate thread/form.

http://www.developer.com/lang/other/article.php/792901

http://www.csharphelp.com/archives/archive90.html

cool thanks for the links, got it working.

Member Avatar for iamthwee

Good. I didn't know if they were useful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.