Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reload + Sleep While Checked?

Status
Not open for further replies.

TehCheeze

Programmer
May 6, 2006
2
US
Simply put.. I am trying to add a Auto Refresh(every 5 seconds) feature to my VB.Net 2005 Project..

This is what I currently have.. I have been playing about with this code for the better part of 8 hours.

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Do Until CheckBox1.Checked = False
RefreshEvery5()
MessageBox.Show("No no no...")
Threading.Thread.Sleep(5000)
CheckBox1.Checked = False
Loop
End Sub


There has to be a way.. This just locks the program. :/ If this method.. Just is not possible. I would settle for the use of 2 radio buttons: On, Off.

Thank you greatly for any and all help.
TehCheeze.
 
I would suggest using a Timer control to achieve what you are doing. Set the interval of the Timer to 5000 (5,000 milliseconds) and then double click the control to bring up the Timer's tick Sub. Put the code that you need to repeat every 5 seconds here.
 
Changed it to..

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
RefreshNow()
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
RefreshNow()
If CheckBox1.Checked = False Then
Timer1.Stop()
End If
End Sub

Runs flawlessly.. Ty Very much. ( I had tried to work with the Timer before.. I was just using it incorrectly. :))

Thank you again.
TehCheeze
 
No problemo! I'm pretty new to VB.NET after migrating from VB6, but aren't we all learning? Good luck in your application, James.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top