Select to view content in your preferred language

Is the GraphicCollection class thread safe?

202
2
Jump to solution
06-05-2024 11:14 AM
Labels (3)
Mike_Quetel
Occasional Contributor

API docs don't explicitly say, but is the GraphicCollection class thread safe?  Use case is that I have a large(ish) number of graphics (25,000 to maybe 100,000)  to add to an overlay.  Can this task be safely chunked into batches and run in parallel? 

0 Kudos
1 Solution

Accepted Solutions
MatveiStefarov
Esri Contributor

The GraphicCollection class is indeed thread-safe (synchronized).  However, the most efficient way to populate it would be to use AddRange method (optimized to reduce temporary allocations and locking/unlocking/eventing overhead).  So, yes, you can absolutely parallelize creation of your Graphic objects -- e.g. using Parallel.ForEach with a partitioner -- but I suggest adding Graphics to the collection in batches of several hundred/thousand rather than individually.

We actually have a whole guide topic dedicated to Graphic performance, check it out for more tips: Performance considerations | ArcGIS Maps SDK for .NET | ArcGIS Developers

A couple years ago we also talked about performance for Graphic-heavy apps at DevSummit.  You can find a recording of it here: "ArcGIS Runtime SDK for .NET: Building Apps - Part 2" (relevant part starts around the 25-minute mark).

View solution in original post

2 Replies
MatveiStefarov
Esri Contributor

The GraphicCollection class is indeed thread-safe (synchronized).  However, the most efficient way to populate it would be to use AddRange method (optimized to reduce temporary allocations and locking/unlocking/eventing overhead).  So, yes, you can absolutely parallelize creation of your Graphic objects -- e.g. using Parallel.ForEach with a partitioner -- but I suggest adding Graphics to the collection in batches of several hundred/thousand rather than individually.

We actually have a whole guide topic dedicated to Graphic performance, check it out for more tips: Performance considerations | ArcGIS Maps SDK for .NET | ArcGIS Developers

A couple years ago we also talked about performance for Graphic-heavy apps at DevSummit.  You can find a recording of it here: "ArcGIS Runtime SDK for .NET: Building Apps - Part 2" (relevant part starts around the 25-minute mark).

Mike_Quetel
Occasional Contributor

Thank you, this is all very useful.  🍻

0 Kudos