|
-
Jul 11th, 2007, 03:45 PM
#1
Thread Starter
Fanatic Member
Re: [2.0] Thread and delegate woes
Many thanks for the links, they are very helpful. I should be able to make some progress now.
Just FYI, I want to get any data received from the serial port back onto the thread the class was created on (which happens to be the UI thread), so that when it is passed to my form, I (or anyone else that uses the class) do not have to check for .InvokeRequired. All the threading stuff is done within the class.
-
Jul 11th, 2007, 06:41 PM
#2
Re: [2.0] Thread and delegate woes
 Originally Posted by Andy_P
Just FYI, I want to get any data received from the serial port back onto the thread the class was created on (which happens to be the UI thread), so that when it is passed to my form, I (or anyone else that uses the class) do not have to check for .InvokeRequired. All the threading stuff is done within the class.
That's exactly what the Timers.Timer and FileSystemWatcher classes do. They have a SynchronizingObject property which, when set, is used to marshal calls to the desired thread. Generally speaking the SynchronizingObject will be a form so that the object raises its events on the UI thread. The code would look something like this:
vb.net Code:
If Me.SynchronizingObject Is Nothing Then
'Use a thread pool thread to raise the event.
ElseIf Me.SynchronizingObject.InvokeRequired Then
'Create a delegate to marshal the call to the thread that owns the synchronising object.
Else
'Raise the event on the current thread.
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|