Results 1 to 4 of 4

Thread: [RESOLVED] [2.0] Thread and delegate woes

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    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.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Thread and delegate woes

    Quote 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:
    1. If Me.SynchronizingObject Is Nothing Then
    2.     'Use a thread pool thread to raise the event.
    3. ElseIf Me.SynchronizingObject.InvokeRequired Then
    4.     'Create a delegate to marshal the call to the thread that owns the synchronising object.
    5. Else
    6.     'Raise the event on the current thread.
    7. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width