定期检查网络通断并做相应处理的程序,运行后不能定期进行网络通断状况检查?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
thread1 = New Threading.Thread(AddressOf MonitorThread)
thread1.Priority = Threading.ThreadPriority.Normal
' thread2 = New Threading.Thread(AddressOf Button_Click)
NetGood = True ’初使设置网络为通
thread1.Start() ‘开始监控线程
End Sub
Private Sub MonitorThread() ‘网络监控子函
Dim pingobj As New Project1.Class1
Do While True
thread1.Sleep(1000)
If pingobj.Ping(1000) = False Then ’pingobj.Ping是检查网络通断的子函
NetGood = False '如网络断,设置标志并暂停线程
thread1.Suspend()
Call RefreshNetConnection() ’刷新网络连接子函
Exit Sub
Else
NetGood = True ‘网络正常
thread1.Sleep(5000) ’五分钟后再进行网络检查
End If
Loop
End Sub
Sub RefreshNetConnection() ...略