我尝试插入一个
While True
do
loop
CheckService()
对于我的跑步功能
Public Function CheckService() As String
Try
Dim filePath As String = "C:\Program Files\OpenVPN Connect\ovpnconnector.cfg"
Try
Using fs As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Using sr As New StreamReader(fs)
Dim line As String
Dim lineNumber As Integer = 0
Do
line = sr.ReadLine()
lineNumber += 1
Loop While (line IsNot Nothing AndAlso lineNumber < 2)
If line IsNot Nothing Then
If line.Length >= 24 Then
Dim i As Char = line(23)
If i = "Y" Then
Label1.Text = "Service Is Running"
Else
Label1.Text = "Service Is Not Running"
End If
End If
Else
Label1.Text = "Service Is Not Installed"
End If
End Using
End Using
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
Catch ex As Exception
MsgBox("Error: " & ex.Message)
End Try
Return Nothing
End Function
我似乎无法让函数循环,我将其添加到表单加载部分,只有当我在循环之外调用该函数时才有效,但它只运行一次
我不确定你的主线代码应该是什么,但你发布的内容甚至看起来都无法编译。 我想你可能想要:
Do
CheckService()
Loop While True