I have an app that uses a display conduit, works well. I am adding a separate task that has some communication activity, that I would like to do on a separate thread than the main(which handles the UI). It also draws geometry based on that, so I have put it on a separate thread. This thread instantiates its own DisplayConduit. The threads don’t need to share any memory(at least for this purpose, maybe in the future). Are there any thread safety issues with this? It seems so; in one of my event driven draw methods, I get an error that the collection changed during enumeration. I can solve this by changing the collection to one of the ‘concurrent’ types in .NET. But I don’t see how its getting changed.
So the question is, should this be a thread safe approach(meaning my error is caused by something else)? Should placing the two conduits on different threads, each only accessed by itself, be safe? Or is there an issue with having two conduits on different threads? I don’t fully understand the rhino event model…which thread is calling the events? Main? My thought is that while I iterating the collection, and drawing things(triggered by an event) the other thread was changing them? But each thread fills its own collections, so I am not sure how this happens?
One clue which is odd, is I have “show threads” turned on in VS. When the error hits, its always the main thread stating its collection has changed. In fact if I set a breakpoint in this method filtered for the secondary thread, it never hits. But I created object IDs in the watch list for the two display conduits, and they are independent (if that is enough to tell). The second conduit draws fine…so it must be working. Its like I just can’t “see” it working. But mostly I just want to learn a bit more about whether this is odd or not.
Edit:
I just saw this:
I always took this to mean “mess with the controls”, in my case wpf. But does “UI” include drawing in the pipeline? If so, that would imply my worker thread needs to modify the main threads display conduit, not create its own…just seems really limiting(there is a large section in the display conduit introduction devoted to not “messing” with other peoples conduits…I assume those could be threaded?)