<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Graphics stays on screen after delete in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1325741#M12082</link>
    <description>&lt;P&gt;Hello, I'm using version 100.12&lt;BR /&gt;My program can have a-lot(can be 10k or even more) of graphics on screen on the same time(static graphics)&lt;BR /&gt;when I work with small or even medium amount of&amp;nbsp;graphics all works fine and well&lt;BR /&gt;But when i work with large amount of&amp;nbsp;graphics, after I delete the graphics from my GraphicCollection(and i checked the count is 0 as expected) the graphics does not disappear from the screen&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;P.S&lt;BR /&gt;Adding&amp;nbsp;graphics to the screen &lt;STRONG&gt;ALWAYS&lt;/STRONG&gt; works fine( when i add 10k+&amp;nbsp;graphics it takes like 5-6 seconds to fully render to the screen)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;P.S2&lt;BR /&gt;I tried to mess around the&amp;nbsp;&lt;SPAN&gt;Partitioner and the&amp;nbsp; Parallel.ForEach parameters&amp;nbsp;but the result stays the same&lt;BR /&gt;&lt;BR /&gt;P.S3&lt;BR /&gt;Changing all&amp;nbsp;Parallel.ForEach not Iterative Foreach yields&amp;nbsp;the same problem&lt;BR /&gt;&lt;BR /&gt;P.S4&lt;BR /&gt;GraphicCollection.Clear()&amp;nbsp;yields&amp;nbsp;the same problem&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private static readonly ConcurrentDictionary&amp;lt;string,Symbol&amp;gt; SymbolDictionary = new ConcurrentDictionary&amp;lt;string,Symbol&amp;gt;();
private readonly ConcurrentBag&amp;lt;Graphic&amp;gt; _slideGrahpics = new readonly ConcurrentBag&amp;lt;Graphic&amp;gt;();
private readonly PolylineBuilder _polylineBuilder = new PolylineBuilder(SpatialReferences.Wgs84);
private readonly PolygonBuilder _polygonBuilder = new PolygonBuilder (SpatialReferences.Wgs84);

public void CreateMapElement(){
    var partitioner = Partitioner.Create(Items, EbumerablePartitionerOptions.NoBuffering);
    Parallel.ForEach(partitioner, new ParallelOptions(){MaxDegreeOfParallesim = 400 , TaskScheduler = TaskScheduler.fromCurrentSynchronizationContext() }, item =&amp;gt; {
   try
   {
        if(item == null || string.IsNullOrEmpty(item.SymbolJson)) return; 
            Symbol symbol;
        if(SymbolDictionary.ContainsKey(item.SymbolJson))
            symbol = SymbolDictionary[item.SymbolJson);
        else
        {
            symbol = Symbol.FromJson(item.SymbolJson); 
            SymbolDictionary.TryAdd(item.SymbolJson, symbol);
        }
        if(!Enum.TryParse(item.GeometryType, ignoreCase: true, result : out GeometryType geometryType)) return;  
        Grahpic grahpic = null;
        switch(geometryType)
        {
            case GeometryType.Point:
                 grahpic = CreateGraphic(item.SymbolLocation.First(), symbol);
            break;
           case GeometryType.Polyline:
                 grahpic = CreateGraphic(_polylineBuilder,item.SymbolLocation, symbol);
            break;
           case GeometryType.Polygon:
                 grahpic = CreateGraphic(_polygonBuilder,item.SymbolLocation, symbol);
            break;
        }
        if(grahpic == null) return;
        grahpic.Attributes[MapConstants.LabelKey] = item.Label;
        _slideGrahpics.add(grahpic)
   }
   catch(Exception ex) {//Handle Exception }
});

}//end CreateMapElement


private Graphic CreateGraphic&amp;lt;T&amp;gt;(MultipartBuider&amp;lt;T&amp;gt; buider, IEnumerable&amp;lt;MapPoint&amp;gt; coordinateCollection, Symbol symbol) where T : Multipart
{
    builder.Parts.Clear();
    foreach(var coordinate in coordinateCollection)
    {
        builder.AddPoint(coordinate);
    } 
    return CreateGraphic(builder.ToGeometry(), symbol);
}//End CreateGraphic&amp;lt;T&amp;gt;

private Graphic CreateGraphic(Geometry geometry, Symbol symbol) =&amp;gt; new Graphic(geometry, symbol); //end CreateGraphic

//this method called AFTER CreateMapElement is finished
private void UpdateActualLayer(string layerId)
{
    var partitioner = Partitioner.Create(_slideGrahpics, EbumerablePartitionerOptions.NoBuffering);
    Parallel.ForEach(partitioner, new ParallelOptions(){MaxDegreeOfParallesim = 400 , TaskScheduler = TaskScheduler.fromCurrentSynchronizationContext() }, grahpic=&amp;gt; {
  GraphicCollection.Add(grahpic);
   });
}//end UpdateActualLayer

//this method called on user click
private void RemoveFromActualLayer(string layerId)
{
    var partitioner = Partitioner.Create(_slideGrahpics, EbumerablePartitionerOptions.NoBuffering);
    Parallel.ForEach(partitioner, new ParallelOptions(){MaxDegreeOfParallesim = 400 , TaskScheduler = TaskScheduler.fromCurrentSynchronizationContext() }, grahpic=&amp;gt; {
  GraphicCollection.Remove(grahpic); //this is 0 when the loop is done
   });//changing to iterative foreach yields the same result
}//end RemoveFromActualLayer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 07:27:01 GMT</pubDate>
    <dc:creator>ofirrosner</dc:creator>
    <dc:date>2023-09-06T07:27:01Z</dc:date>
    <item>
      <title>Graphics stays on screen after delete</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1325741#M12082</link>
      <description>&lt;P&gt;Hello, I'm using version 100.12&lt;BR /&gt;My program can have a-lot(can be 10k or even more) of graphics on screen on the same time(static graphics)&lt;BR /&gt;when I work with small or even medium amount of&amp;nbsp;graphics all works fine and well&lt;BR /&gt;But when i work with large amount of&amp;nbsp;graphics, after I delete the graphics from my GraphicCollection(and i checked the count is 0 as expected) the graphics does not disappear from the screen&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;P.S&lt;BR /&gt;Adding&amp;nbsp;graphics to the screen &lt;STRONG&gt;ALWAYS&lt;/STRONG&gt; works fine( when i add 10k+&amp;nbsp;graphics it takes like 5-6 seconds to fully render to the screen)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;P.S2&lt;BR /&gt;I tried to mess around the&amp;nbsp;&lt;SPAN&gt;Partitioner and the&amp;nbsp; Parallel.ForEach parameters&amp;nbsp;but the result stays the same&lt;BR /&gt;&lt;BR /&gt;P.S3&lt;BR /&gt;Changing all&amp;nbsp;Parallel.ForEach not Iterative Foreach yields&amp;nbsp;the same problem&lt;BR /&gt;&lt;BR /&gt;P.S4&lt;BR /&gt;GraphicCollection.Clear()&amp;nbsp;yields&amp;nbsp;the same problem&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private static readonly ConcurrentDictionary&amp;lt;string,Symbol&amp;gt; SymbolDictionary = new ConcurrentDictionary&amp;lt;string,Symbol&amp;gt;();
private readonly ConcurrentBag&amp;lt;Graphic&amp;gt; _slideGrahpics = new readonly ConcurrentBag&amp;lt;Graphic&amp;gt;();
private readonly PolylineBuilder _polylineBuilder = new PolylineBuilder(SpatialReferences.Wgs84);
private readonly PolygonBuilder _polygonBuilder = new PolygonBuilder (SpatialReferences.Wgs84);

public void CreateMapElement(){
    var partitioner = Partitioner.Create(Items, EbumerablePartitionerOptions.NoBuffering);
    Parallel.ForEach(partitioner, new ParallelOptions(){MaxDegreeOfParallesim = 400 , TaskScheduler = TaskScheduler.fromCurrentSynchronizationContext() }, item =&amp;gt; {
   try
   {
        if(item == null || string.IsNullOrEmpty(item.SymbolJson)) return; 
            Symbol symbol;
        if(SymbolDictionary.ContainsKey(item.SymbolJson))
            symbol = SymbolDictionary[item.SymbolJson);
        else
        {
            symbol = Symbol.FromJson(item.SymbolJson); 
            SymbolDictionary.TryAdd(item.SymbolJson, symbol);
        }
        if(!Enum.TryParse(item.GeometryType, ignoreCase: true, result : out GeometryType geometryType)) return;  
        Grahpic grahpic = null;
        switch(geometryType)
        {
            case GeometryType.Point:
                 grahpic = CreateGraphic(item.SymbolLocation.First(), symbol);
            break;
           case GeometryType.Polyline:
                 grahpic = CreateGraphic(_polylineBuilder,item.SymbolLocation, symbol);
            break;
           case GeometryType.Polygon:
                 grahpic = CreateGraphic(_polygonBuilder,item.SymbolLocation, symbol);
            break;
        }
        if(grahpic == null) return;
        grahpic.Attributes[MapConstants.LabelKey] = item.Label;
        _slideGrahpics.add(grahpic)
   }
   catch(Exception ex) {//Handle Exception }
});

}//end CreateMapElement


private Graphic CreateGraphic&amp;lt;T&amp;gt;(MultipartBuider&amp;lt;T&amp;gt; buider, IEnumerable&amp;lt;MapPoint&amp;gt; coordinateCollection, Symbol symbol) where T : Multipart
{
    builder.Parts.Clear();
    foreach(var coordinate in coordinateCollection)
    {
        builder.AddPoint(coordinate);
    } 
    return CreateGraphic(builder.ToGeometry(), symbol);
}//End CreateGraphic&amp;lt;T&amp;gt;

private Graphic CreateGraphic(Geometry geometry, Symbol symbol) =&amp;gt; new Graphic(geometry, symbol); //end CreateGraphic

//this method called AFTER CreateMapElement is finished
private void UpdateActualLayer(string layerId)
{
    var partitioner = Partitioner.Create(_slideGrahpics, EbumerablePartitionerOptions.NoBuffering);
    Parallel.ForEach(partitioner, new ParallelOptions(){MaxDegreeOfParallesim = 400 , TaskScheduler = TaskScheduler.fromCurrentSynchronizationContext() }, grahpic=&amp;gt; {
  GraphicCollection.Add(grahpic);
   });
}//end UpdateActualLayer

//this method called on user click
private void RemoveFromActualLayer(string layerId)
{
    var partitioner = Partitioner.Create(_slideGrahpics, EbumerablePartitionerOptions.NoBuffering);
    Parallel.ForEach(partitioner, new ParallelOptions(){MaxDegreeOfParallesim = 400 , TaskScheduler = TaskScheduler.fromCurrentSynchronizationContext() }, grahpic=&amp;gt; {
  GraphicCollection.Remove(grahpic); //this is 0 when the loop is done
   });//changing to iterative foreach yields the same result
}//end RemoveFromActualLayer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 07:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1325741#M12082</guid>
      <dc:creator>ofirrosner</dc:creator>
      <dc:date>2023-09-06T07:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Graphics stays on screen after delete</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1325769#M12083</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Can you try updating to version 100.15.2 and retesting?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 09:15:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1325769#M12083</guid>
      <dc:creator>MichaelBranscomb</dc:creator>
      <dc:date>2023-09-06T09:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Graphics stays on screen after delete</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1326322#M12092</link>
      <description>&lt;P&gt;I need to check if i can upgrade&lt;BR /&gt;but in the meanwhile is there anything i can do?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 12:22:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/graphics-stays-on-screen-after-delete/m-p/1326322#M12092</guid>
      <dc:creator>ofirrosner</dc:creator>
      <dc:date>2023-09-07T12:22:55Z</dc:date>
    </item>
  </channel>
</rss>

