A
Andy Roxburgh
Hi All
I'm trying to get my head around threads in VB.NET CF.
I want to call a function from a worker thread. This function handles
data communications from an interface card. The interface card has a
driver DLL, commsdriver.dll, which is declared in my application. The
nitty gritty of my code is as follows:
-----------------------------------------------
Structure sTS
Public day As Int16
Public hour As Byte
Public min As Byte
Public sec As Int16
Public ms As Int16
Public us As Int16
End Structure
Structure sMsg
Public ff As Byte ' frame format
Public ftf As Byte ' frame type flag
Public len As Byte '
Public id As Integer ' message id
Public data0 As Byte ' data payload
Public data1 As Byte
Public data2 As Byte
Public data3 As Byte
Public data4 As Byte
Public data5 As Byte
Public data6 As Byte
Public data7 As Byte
Public timestamp As sTS ' message timestamp
End Structure
' globals
Public msg_list(50) As sMsg
Public msg_list_size As Integer
Public Declare Function ReadData Lib "commsdriver.dll" (ByVal Board As
Byte, ByRef MsgList As sMsg, ByVal timeout As Int32, ByRef ListSize As
Int32) As Int32
Dim worker_thread As New System.Threading.Thread(AddressOf
comms_routine)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'...... form1_load code ....
'----- Set up the threads
worker_thread.Priority = Threading.ThreadPriority.Normal
worker_thread.Start()
'...... rest of form1_load code ....
End Sub
Public Sub comms_routine()
Dim Status As Integer
'worker thread : pull 50 messages from rx buffer
While (True)
msg_list_size = 50
Status = ReadData(1, msg_list(0), 5, msg_list_size)
'.... do rest of processing....
End While
End Sub
----------------------------------
It hangs on
Status = ReadData(1, msg_list(0), 5, msg_list_size)
After going through this newsgroup, I guess this happens because I
have to make this call from the main UI, so I have to use
Control.Invoke, right?
As I'm fairly new to VB.NET CF, I'm having a hard time understanding
the documentation on the MSDN website pertaining to Control.Invoke.
Can someone give me a few pointers as to how I proceed? So far I've
found example code which I've tried but it was calling methods that
accepted different arguments to what I have here and I'm banging my
head against a wall trying to figure out how to make it work.
Any help appreciated!
Andy
I'm trying to get my head around threads in VB.NET CF.
I want to call a function from a worker thread. This function handles
data communications from an interface card. The interface card has a
driver DLL, commsdriver.dll, which is declared in my application. The
nitty gritty of my code is as follows:
-----------------------------------------------
Structure sTS
Public day As Int16
Public hour As Byte
Public min As Byte
Public sec As Int16
Public ms As Int16
Public us As Int16
End Structure
Structure sMsg
Public ff As Byte ' frame format
Public ftf As Byte ' frame type flag
Public len As Byte '
Public id As Integer ' message id
Public data0 As Byte ' data payload
Public data1 As Byte
Public data2 As Byte
Public data3 As Byte
Public data4 As Byte
Public data5 As Byte
Public data6 As Byte
Public data7 As Byte
Public timestamp As sTS ' message timestamp
End Structure
' globals
Public msg_list(50) As sMsg
Public msg_list_size As Integer
Public Declare Function ReadData Lib "commsdriver.dll" (ByVal Board As
Byte, ByRef MsgList As sMsg, ByVal timeout As Int32, ByRef ListSize As
Int32) As Int32
Dim worker_thread As New System.Threading.Thread(AddressOf
comms_routine)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'...... form1_load code ....
'----- Set up the threads
worker_thread.Priority = Threading.ThreadPriority.Normal
worker_thread.Start()
'...... rest of form1_load code ....
End Sub
Public Sub comms_routine()
Dim Status As Integer
'worker thread : pull 50 messages from rx buffer
While (True)
msg_list_size = 50
Status = ReadData(1, msg_list(0), 5, msg_list_size)
'.... do rest of processing....
End While
End Sub
----------------------------------
It hangs on
Status = ReadData(1, msg_list(0), 5, msg_list_size)
After going through this newsgroup, I guess this happens because I
have to make this call from the main UI, so I have to use
Control.Invoke, right?
As I'm fairly new to VB.NET CF, I'm having a hard time understanding
the documentation on the MSDN website pertaining to Control.Invoke.
Can someone give me a few pointers as to how I proceed? So far I've
found example code which I've tried but it was calling methods that
accepted different arguments to what I have here and I'm banging my
head against a wall trying to figure out how to make it work.
Any help appreciated!
Andy