lsacchetti
Member
- Joined
- Mar 23, 2010
- Messages
- 6
- Programming Experience
- 5-10
I've a class with a timer inside
This timer is enabled in the New() of the class
The timer tick is managed by the function ReadPlcRes
My problem is: I'm in a try..catch..finally statement. I supposed that no matter what happen in the try section. But sometimes the thread blocks as he never get out from this routine (and of course he did it, I'm sure)
I'he tried also with no autoreset, putting tt.start in the Finally branch, but the result is the same.
Anyone experienced some like that? Any idea?
VB.NET:
Private tt As New System.Timers.Timer()
This timer is enabled in the New() of the class
VB.NET:
Try
tt.AutoReset = True
tt.Interval = TimerPlcMan 'about 100 ms
AddHandler tt.Elapsed, AddressOf ReadPlcRes
tt.Enabled = True
_tmrWork = False
Catch ex As Exception
_LastError = ex.ToString
End Try
VB.NET:
Private Sub ReadPlcRes(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
If _tmrWork Then
Exit Sub
End If
_tmrWork = True
Dim start As Date = Now()
Dim lbuff(-1) As PlcMessageStruct
Try
For Each cnn As IPlcConn In _listaConn
Do While cnn.MessageCount > 0
Dim msg As PlcMessageStruct = cnn.GetMessage
If Not msg.Id Is Nothing Then
ReDim Preserve lbuff(lbuff.Count)
lbuff(lbuff.Count - 1) = msg
End If
Loop
Next
If lbuff.Count > 0 Then RaiseEvent NewPlcMessages(lbuff)
Catch ex As Exception
_myLog.WriteEv("ReadPlcRes", LogCentralizer.LogType.logAlarms, ex.ToString)
Finally
_tmrWork = False
End Try
End Sub
I'he tried also with no autoreset, putting tt.start in the Finally branch, but the result is the same.
Anyone experienced some like that? Any idea?
Last edited: