I have a Windows service that runs perfect. It checks a print-Q and deletes unwanted jobs. The problem I'm having is when I monitor the Mem Usage in Windows Task Manager I notice that the amount of memory used by the web service keeps increasing to a dangerous piont. I'm trying to find what causes the memory to increase.
My windows service uses a time object with interval=4000. and below is the only code I would like to run.
PrivateSub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim kNameSpace AsString = "root\cimv2"
Dim DocName AsString = "HL7"
Dim Jobs
Dim oJob
Dim oService
Dim oLocator
oService = Nothing
oLocator = CreateObject("WbemScripting.SWbemLocator")
oService = oLocator.ConnectServer(, kNameSpace, , )
oService.Security_.impersonationlevel = 3
' Required to perform administrative tasks on the spooler service
oService.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
Jobs = oService.InstancesOf("Win32_PrintJob")
ForEach oJob In Jobs
If Mid(oJob.Document, 1, 3) = DocName Then
Try
oJob.Delete_()
Catch ex As Exception
EndTry
EndIf
Next
oService.Dispose()
oLocator.Dispose()
Jobs.Dispose()
oJob.Dispose()
DocName = Nothing
kNameSpace = Nothing
e = Nothing
sender.dispose()
EndSub
My windows service uses a time object with interval=4000. and below is the only code I would like to run.
PrivateSub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim kNameSpace AsString = "root\cimv2"
Dim DocName AsString = "HL7"
Dim Jobs
Dim oJob
Dim oService
Dim oLocator
oService = Nothing
oLocator = CreateObject("WbemScripting.SWbemLocator")
oService = oLocator.ConnectServer(, kNameSpace, , )
oService.Security_.impersonationlevel = 3
' Required to perform administrative tasks on the spooler service
oService.Security_.Privileges.AddAsString("SeLoadDriverPrivilege")
Jobs = oService.InstancesOf("Win32_PrintJob")
ForEach oJob In Jobs
If Mid(oJob.Document, 1, 3) = DocName Then
Try
oJob.Delete_()
Catch ex As Exception
EndTry
EndIf
Next
oService.Dispose()
oLocator.Dispose()
Jobs.Dispose()
oJob.Dispose()
DocName = Nothing
kNameSpace = Nothing
e = Nothing
sender.dispose()
EndSub