Private Sub Updatetimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Updatetimer.Tick
Dim T As Threading.Thread
Try
Del = New CheckPIMDelegate(AddressOf CheckPIM)
Dim cb As New AsyncCallback(AddressOf Me.CheckPIMComplete)
Del.BeginInvoke(cb, Del)
Catch ex As Exception
Trace.WriteLine("error while starting new thread:" & ex.Message)
End Try
End Sub
Private Sub CheckPIMComplete(ByVal ar As IAsyncResult)
'gets called when thread complete
'copy from private to shared to avoid conflict
Del.EndInvoke(ar)
Trace.WriteLine("Thread ended")
Me.LastBatchNumber = Me.tLBN
Me.RTSvalue = Me.tRTS
End Sub
Private Delegate Sub CheckPIMDelegate()
Private Sub CheckPIM()
Dim s As String
Dim srv As Server
Dim pt As PIPoint
Dim inst As New PISDK.PISDKClass
Dim i As Integer = 0
Dim dflt As Integer = 0
Dim d As PISDK.PIData
Dim v As PISDK.PIValue
Dim ptAtr As PointAttribute
Dim numb As New Regex("[0-9]+")
Dim bName As New Regex("[a-z]+", RegexOptions.IgnoreCase)
Dim m As Match
Try
srv = inst.Servers("pika")
pt = srv.PIPoints("AC240_BatchID")
d = pt.Data
v = d.Snapshot
s = v.Value
s = s.Trim
s = s.Replace("--", "")
Threading.Thread.CurrentThread.Sleep(0)
If s.Length > 2 And v.IsGood Then
Me.LastBatchNumber.Total = v.Value
m = numb.Match(s)
If m.Success Then
Me.tLBN.Number = m.Value
End If
m = bName.Match(s)
If m.Success Then
Me.tLBN.Letters = m.Value
End If
Else
End If
pt = srv.PIPoints("AC240_YNT01")
d = pt.Data
v = d.Snapshot
Threading.Thread.CurrentThread.Sleep(0)
If v.IsGood AndAlso v.TimeStamp.LocalDate.AddMinutes(10) > Now Then
'data is good
Me.tRTS = v.Value
Else
Me.tRTS = 0
End If
s = s.Trim
Catch ex As Exception
Trace.Write("Error while connecting to PIM")
Trace.WriteLine(ex.Message)
Finally
srv.Close()
srv = Nothing
d = Nothing
v = Nothing
pt = Nothing
End Try
End Sub