Update the method SubscriptionUpdate
Private Sub SubscriptionUpdate(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs)
While Not StopSubscriptions
If Not m_DisableSubscriptions And GroupedSubscriptionReads IsNot Nothing Then
'* 3-JUN-13 Do not read data until handles are created to avoid exceptions
If Not HandleCreated AndAlso m_SynchronizingObject IsNot Nothing Then
If m_SynchronizingObject IsNot Nothing AndAlso TypeOf (m_SynchronizingObject) Is System.Windows.Forms.Control _
Then
If Not DirectCast(m_SynchronizingObject, System.Windows.Forms.Control).IsHandleCreated Then
'Exit Sub
Else
HandleCreated = True
End If
End If
Else
Dim i As Integer = 0
While i < GroupedSubscriptionReads.Count And Not StopSubscriptions
SyncLock (ReadLock) ' Do not let the Internal request change during another read
Try
If Not m_DisableSubscriptions Then
InternalRequest = True
'Dim elapsed = timer.ElapsedMilliseconds
'23-OCT-11 Moved before the next 4 lines
Me.Read(GroupedSubscriptionReads(i).TagName, GroupedSubscriptionReads(i).NumberToRead)
'elapsed = timer.ElapsedMilliseconds
InternalRequest = False
Else
Threading.Thread.Yield()
End If
Catch ex As MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException
Dim x As New MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs(ex.ErrorCode, ex.Message)
x.Values.Add(ex.Message)
Dim z() As Object = {Me, x}
Try
'**** TODO: Send error to proper control(i indexes the grouped subscriptions, not individual subscription)
If m_SynchronizingObject IsNot Nothing Then
m_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallBack, z)
Else
If SubscriptionList(i).dlgCallBack IsNot Nothing Then
SubscriptionList(i).dlgCallBack.Invoke(Me, x)
End If
End If
Catch ex2 As Exception
End Try
Catch ex As Exception
'* Send this message back to the requesting control
Dim x As New MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs(-99, ex.Message)
x.Values.Add(ex.Message)
Dim z() As Object = {Me, x}
'**** TODO: Send error to control
'm_SynchronizingObject.BeginInvoke(SubscriptionList(i).dlgCallBack, z)
'* Slow down the poll rate to avoid app freezing
SubscriptionList(i).SkipReads = 10
End Try
End SyncLock
i += 1
End While
End If
End If
Threading.Thread.Sleep(m_PollRateOverride)
End While
End Sub