I am using AGSGraphicsOverlay to display custom AGSGraphics. The graphics' manipulation logic I want to put into an async thread. So what are the general rules regarding usage of arcgis core objects: layers, graphics, map in multithreading environment? I am getting rarely com.esri.arcgis.runtime.error Code=24, and trying to figure out all rules to avoid it.
Hello and thank you for your question! In general when performing async/multithreaded operation, the main rule is to make sure all display/map interactions happen on the main thread. I don't see any issues doing some background/async processing of graphics and adding them to a graphics overlay, then when complete, adding the overlay to the map.
Do you have any more information about your "Code=24" error or maybe a call stack? That error seems to indicate that an object was assigned to more than one parent object, which is not allowed; example: a single layer object being added to two map views, or maybe a single graphics object being added to two or more graphic overlays.
If you have more information, I'm happy to take a look at it. Thanks.
Mark
I suspect that the issue was caused when I tried to remove a graphic which isn't on the graphicsOverlay. I remove and add back a graphic which is selected to make it appear on the top of all graphics. Simple graphicsOverlay.contains(graphic) seems to be helping me avoiding the error.
What is about `graphicsOverlay.graphics.addObjects()`, the graphicsOverlay is already added to AGSMapView and I am manipulating data on background thread and then call `graphicsOverlay.graphics.addObjects()` on the same thread. Can it cause issues? I haven't seen any but my tests can be insufficient.
And is it ok to read existing graphics `graphicsOverlay.graphics` from a background thread?
Yes, it is OK to use a background thread to process, add and read graphics to/from an overlay. In fact, there is a performance boost to doing it that way as opposed to on the main thread.