My vb.net service has a timer that ticks every minute or so, but before executing it checks if the previous thread has been completed (I don’t want duplicate results)
The problem is that at some times the process just get hung in the process, so I wrote that if the process is not finish within 5 minutes it should continue executing.
Now I have a few hung threads in the application… eating resources for nothing.
So my question is if I could kill those threads.
Protected Overrides Sub OnStart(ByVal args() As String)
EmailTimer = New System.Timers.Timer(50000)
EmailTimer.AutoReset = True
AddHandler EmailTimer.Elapsed, AddressOf CheckNewEmails
EmailTimer.Start()
End Sub
worker code:
Private Sub CheckNewEmails(ByVal sender As Object, e As System.Timers.ElapsedEventArgs)
If _workStartTime <> DateTime.MinValue Then
' check how much time has elapsed since work started previously
If DateDiff(DateInterval.Minute, _workStartTime, Now) > 5 Then
_workStartTime = DateTime.MinValue
End If
Else
_workStartTime = DateTime.Now
Dim client As New ImapClient()
client.Connect("imap.gmail.com", 993) 'that line could sleep forever..
End if
_workStartTime = DateTime.Now
End Sub