【发布时间】:2017-09-15 01:27:16
【问题描述】:
我正在使用计时器和 System.ServiceProcess 命名空间来检查 Windows 服务的状态。我做得很成功,但应用程序的内存使用量不断上升。这是我的代码,我在这里缺少什么?服务控制器已经在 using 块中。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
servicetimer.AutoReset = True
servicetimer.Interval = 1
AddHandler servicetimer.Elapsed, AddressOf tick
servicetimer.Enabled = True
servicetimer.Start()
End Sub
Private Sub tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
Using sc As New ServiceController("Smart Card")
If sc.Status = ServiceControllerStatus.Stopped Or sc.Status = ServiceControllerStatus.StopPending Then
'Do stuff when stopped
ElseIf sc.Status = ServiceControllerStatus.Running Or sc.Status = ServiceControllerStatus.StartPending Then
'Do Stuff when started
Else
End If
End Using
End Sub
【问题讨论】:
-
您确定泄漏不在代码的“做事”部分吗? (换句话说,您是否用 just 上面显示的代码重现了问题?)
-
@HarryJohnston "do stuff" 部分目前只是设置标签文本以显示服务的当前状态,我已将其删除以检查并且泄漏仍然发生。
标签: .net vb.net winforms windows-services