Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Event Handling between Threads

Event Handling between Threads

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpwpfdesigndata-structures
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AeroClassics
    wrote on last edited by
    #1

    Sorry for the cross post but this doesn't fit neatly into Silverlight/WPF! I am asking this in the WPF forum because this is a WPF app but this question does not necessarily pertain to WPF, i.e. the UI thread. Here is the scenario: I have three (3) threads. Thread One (1) call it the Master Thread; Thread Two (2) is a Ethernet Comm thread; and Thread Three (3) is a GPIB comm thread. Both communication threads handle asynchronous communications from remote entities. At this time there is only one entity hanging off each comm type. I have implemented a mix of EventWaitHandles and delegates. This all works pretty well. Just think this architecture is a bit ...... ugly. So which one is better/safer? My concern is as follows. With delegates, for example, the Master thread registers an event handler with Thread 2 and an event handler with Thread 3 for messages that come in. Obviously data could come in near simultaneously. So Thread 2 encases a message in an EventArg and invokes the event on the Master thread. The Master Thread begins processing and then Thread 3 encases its message in an EventArg and invokes the event on the Master Thread. What happens? Does the Master Thread stop in the middle of handling the first event to service the second one? Does the second event wait until the first event is processed? What if Thread 2 gets another message and invokes the event again while the Master is processing the first event? I wonder if using a queue and an manual Reset EventWaitHandle is not a better idea as the Thread 2 can check the status and wait until it is reset before putting the message in the queue and setting the EventWaitHandle again. Opinions, please? Thanks, Doug

    I am a Traveler of both Time and Space

    L 1 Reply Last reply
    0
    • A AeroClassics

      Sorry for the cross post but this doesn't fit neatly into Silverlight/WPF! I am asking this in the WPF forum because this is a WPF app but this question does not necessarily pertain to WPF, i.e. the UI thread. Here is the scenario: I have three (3) threads. Thread One (1) call it the Master Thread; Thread Two (2) is a Ethernet Comm thread; and Thread Three (3) is a GPIB comm thread. Both communication threads handle asynchronous communications from remote entities. At this time there is only one entity hanging off each comm type. I have implemented a mix of EventWaitHandles and delegates. This all works pretty well. Just think this architecture is a bit ...... ugly. So which one is better/safer? My concern is as follows. With delegates, for example, the Master thread registers an event handler with Thread 2 and an event handler with Thread 3 for messages that come in. Obviously data could come in near simultaneously. So Thread 2 encases a message in an EventArg and invokes the event on the Master thread. The Master Thread begins processing and then Thread 3 encases its message in an EventArg and invokes the event on the Master Thread. What happens? Does the Master Thread stop in the middle of handling the first event to service the second one? Does the second event wait until the first event is processed? What if Thread 2 gets another message and invokes the event again while the Master is processing the first event? I wonder if using a queue and an manual Reset EventWaitHandle is not a better idea as the Thread 2 can check the status and wait until it is reset before putting the message in the queue and setting the EventWaitHandle again. Opinions, please? Thanks, Doug

      I am a Traveler of both Time and Space

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I have a similar case: multiple threads accessing temperature controllers over a serial port; a temperature charting thread; another handling user interaction. When I need to access a shared resource (like the serial port), I’ve been using a C# “lock” at the appropriate point to block a competing thread. It’s been working well and does not require the threads to do anything “special” (other than insure all requests are short in duration so as not to tie up any one thread for an extended amount of time).

      A 1 Reply Last reply
      0
      • L Lost User

        I have a similar case: multiple threads accessing temperature controllers over a serial port; a temperature charting thread; another handling user interaction. When I need to access a shared resource (like the serial port), I’ve been using a C# “lock” at the appropriate point to block a competing thread. It’s been working well and does not require the threads to do anything “special” (other than insure all requests are short in duration so as not to tie up any one thread for an extended amount of time).

        A Offline
        A Offline
        AeroClassics
        wrote on last edited by
        #3

        Good solution! I am using that in a couple of places and that helps. More I am trying to avoid a mix of EventWaitHandles and delegate/event handlers. I think this is a bit "messy" looking. But with schedule tight sometimes you just have to do what you have to do ;-) Doug

        I am a Traveler of both Time and Space

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups