I'll help Andy out... Without the full program I've not been able to test it, but the following should work. Let me know if it doesn't. :-)
As to an easier way, I'm not sure of one. On the full framework, I'd recommend the BackgroundWorker and call ReportProgress(name, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), name) to update the UI, and it would handle the thread switching. But it's not included in the CF, an odd decision to my mind...
Public Sub DealWithRequest_WithThreadCompatibleUiUpdating()
While ol.IsListening = True
Dim olc As ObexListenerContext
olc = ol.GetContext
Dim olr As ObexListenerRequest
olr = olc.Request
Dim filename As String
Dim path As String
Dim specchar As Char
specchar = "/"
filename = ObexUri.UnescapeDataString(olr.RawUrl.TrimStart(specchar))
path = "\My Documents"
Dim bep As BluetoothEndPoint = CType(olr.RemoteEndPoint, BluetoothEndPoint)
Dim bdi As New Sockets.BluetoothDeviceInfo(bep.Address)
Dim name As String = bdi.DeviceName
olr.WriteFile(path + "\\" + " " + filename)
UpdateTheUi(filename, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), name)
End While
End Sub
' This delegate enables asynchronous calls for setting
' Control properties on the Form.
Delegate Sub UpdateTheUiCallback(filename As String, time As String, name As String)
' This method demonstrates a pattern for making thread-safe
' calls on a Windows Forms control.
Sub UpdateTheUi(filename As String, time As String, name As String)
If Me.Label2.InvokeRequired Then
' We've found that we're attempting to update the Form from
' a different thread to the one that created it. So use
' Control's BeginInvoke method to request a callback of ourselves
' with the same arguments, but on the UI thread! :-)
Dim callback As New UpdateTheUiCallback(AddressOf UpdateTheUi)
Me.BeginInvoke(callback, New Object() { filename, time, name })
Exit Sub
End If
' Now we're on the UI thread, access the Controls' properties as normal :-)
Me.Label2.Text = filename
Me.Label3.Text = time
Me.Label4.Text = name
End Sub
Alan J. McFarlane
http://www.alanjmcf.me.uk/
Please follow-up in the newsgroup for the benefit of all.
Have I helped? Consider visiting my Amazon wishlist, see my homepage.