Refreshing every minutes
In a form, there is a label. It shows whether web service is connected or not at every minutes. How to code to repeat this process? W开发者_StackOverflow中文版ill I use the thread or timer? Please share me.
You will need a timer object in order to run the code every X minutes. Using a separate thread to check the web service only needs to be done if it will take a while to check and you want your form to remain responsive during this time.
Using a timer is very easy:
Private WithEvents timer As New System.Timers.Timer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Set interval to 1 minute
timer.Interval = 60000
'Synchronize with current form, or else an error will occur when trying to
'update the UI from within the elapsed event
timer.SynchronizingObject = Me
End Sub
Private Sub timer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer.Elapsed
'Add code here to check if the web service is updated and update label
End Sub
精彩评论