2011-10-03 180 views
0

在表单中有一个标签。它显示Web服务是否在每分钟连接。如何编码重复这个过程?我会使用线程还是计时器?请分享我。每分钟刷新一次

+1

首先 - 你为什么要保持网络服务开放的,如果你的不是真正使用它? – pingoo

+0

类定时器下没有.SynchronizingObject方法 – Mwenyeji

回答

1

您需要一个计时器对象才能每X分钟运行一次代码。使用单独的线程来检查Web服务只需要花费一些时间来检查并且希望表单在此期间保持响应。

使用计时器非常简单:

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