hi,
I'm have a quite big application which have 2 serial ports and access 1 DB (running on Background workers). I'm experiencing some random locks while the application is running and I started looking for something that could cause it.
One of the obvious possibilities would be if I had in the GUI thread some While_End that would never return.
I have one While_End in my GUI thread but IMHO it does not look like it would lock, so I want your opinion: Does the code below looks like will lock?? If 'yes', Why ?
This StopWorker method is called by different areas of my application when they have to use the serial port to send commands.
From my point of view, the only way for the BGWorker not to see the CancellationPending it would be if the Serial.ReadMessage() never returns, but that method is a simply:
plus a few extra Try-Catch; Return True or False bits.
Does anyone can imagine a scenario where this While_End would not return ??
thanks
I'm have a quite big application which have 2 serial ports and access 1 DB (running on Background workers). I'm experiencing some random locks while the application is running and I started looking for something that could cause it.
One of the obvious possibilities would be if I had in the GUI thread some While_End that would never return.
I have one While_End in my GUI thread but IMHO it does not look like it would lock, so I want your opinion: Does the code below looks like will lock?? If 'yes', Why ?
VB.NET:
Private Sub CommsReader_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles CommsReader.DoWork
While Not CommsReader.CancellationPending
' Read
If Serial.ReadMessage() Then ' If read successful
CommsReader.ReportProgress(1) ' Reports 1 = good read, update screen
Else ' If Timeout
CommsReader.ReportProgress(-1) ' Report -1 = time out
Exit While ' Stops the coms reader
End If
' Awaits for next message
r.Sleep(800)
End While
End Sub
Public Function StopWorker() As Boolean
CommsReader.CancelAsync() ' Cancels the reader thread and awaits
While CommsReader.IsBusy ' Awaits the thread to end
r.Sleep(200)
Try
Application.DoEvents()
Catch ex As Exception
r.ErrorLog(ex.Message)
End Try
End While
StopWorker = True
End Function
This StopWorker method is called by different areas of my application when they have to use the serial port to send commands.
From my point of view, the only way for the BGWorker not to see the CancellationPending it would be if the Serial.ReadMessage() never returns, but that method is a simply:
VB.NET:
For i = 0 To 18
WTU.Analogues(i) = WTUConn.Read(", ")
Next i
WTU.Analogues(19) = WTUConn.Read(vbCr)
Does anyone can imagine a scenario where this While_End would not return ??
thanks