我有一个简单的GUI,我只是存储系统信息并显示结果。
两个问题区域是detectADUC
和detectExchange
Sub。相应标签更新的唯一时间是我在form_load事件中将一个放在订单上方。
我想也许我需要释放一些东西?我在某个地方持有价值吗?请看下面的内容。
detectExchange
Private Sub detectExchange()
Dim exchange As New ServiceController("Microsoft Exchange Service Host")
Try
If exchange.Status.Equals(ServiceControllerStatus.Running) Or exchange.Status.Equals(ServiceControllerStatus.StartPending) Then
Label9.Text = "Detected - Running"
End If
Catch ex As InvalidOperationException
Label9.ForeColor = Color.Red
Label9.Text = "NOT INSTALLED"
End Try
If exchange.Status.Equals(ServiceControllerStatus.Stopped) Or exchange.Status.Equals(ServiceControllerStatus.StopPending) Then
Label9.Text = "Detected - NOT RUNNING"
End If
End Sub
detectADUC
Private Sub detectADUC()
Dim aduc As New ServiceController("Active Directory Domain Services")
Try
If aduc.Status.Equals(ServiceControllerStatus.Running) Or aduc.Status.Equals(ServiceControllerStatus.StartPending) Then
Label10.Text = "Detected - Running"
End If
Catch ex As InvalidOperationException
Label10.ForeColor = Color.Red
Label10.Text = "NOT INSTALLED"
End Try
If aduc.Status.Equals(ServiceControllerStatus.Stopped) Or aduc.Status.Equals(ServiceControllerStatus.StopPending) Then
Label10.Text = "Detected - NOT RUNNING"
End If
End Sub
调用潜艇
Private Sub systemchecks_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RichTextBox1.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") & (": installation launched")
Label12.Text = getExternalIP()
getHostname()
hardwareID()
detectOS()
detectADUC()
detectExchange()
hardwareID()
End Sub
正如您所看到的,唯一不同的是变量名称,服务名称和更新的标签。 - 但是只有一个标签会更新,具体取决于我在form_load中首先调用的那个。
我尝试过使用Me.Refresh
, - 我尝试添加一个新类,然后创建一个公共共享子,然后在form_load中引用它。
我甚至将交换异常捕获重命名为ex2
有人可以解释这个问题,以便我能理解并避免将来出现问题吗?
答案 0 :(得分:0)
我自己设法解决了这个问题,见下文。
Private Sub detectExchange()
Dim exchange As New ServiceController("Microsoft Exchange Service Host")
Try
If exchange.Status.Equals(ServiceControllerStatus.Running) Or exchange.Status.Equals(ServiceControllerStatus.StartPending) Then
Label9.Text = "Detected - Running"
Else
End If
If exchange.Status.Equals(ServiceControllerStatus.Stopped) Or exchange.Status.Equals(ServiceControllerStatus.StopPending) Then
Label9.Text = "Detected - NOT RUNNING"
End If
Catch ex As InvalidOperationException
Label9.ForeColor = Color.Red
Label9.Text = "NOT INSTALLED"
End Try
End Sub
Private Sub detectADUC()
Dim aduc As New ServiceController("Active Directory Domain Services")
Try
If aduc.Status.Equals(ServiceControllerStatus.Running) Or aduc.Status.Equals(ServiceControllerStatus.StartPending) Then
Label10.Text = "Detected - Running"
Else
End If
If aduc.Status.Equals(ServiceControllerStatus.Stopped) Or aduc.Status.Equals(ServiceControllerStatus.StopPending) Then
Label10.Text = "Detected - NOT RUNNING"
End If
Catch ex As InvalidOperationException
Label10.ForeColor = Color.Red
Label10.Text = "NOT INSTALLED"
End Try
End Sub