I'm not sure why I'm getting this error but it is probably simple-I run an IdentifyTask that then runs a Buffer on all the Identified Features. For some reason, it seems as though BufferCompleted is running +1 for every mouse click. IE, on my 2nd identify task it will run two times, 3rd identify task it runs 3 times and so on.Any ideas?
void IdentifyTask2_ExecuteCompleted(object sender, IdentifyEventArgs args )
{
GraphicsLayer layer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
layer.ClearGraphics();
bp.Features.Clear();
toBuffer.Clear();
//shows us how many features are identified - for testing
MessageBox.Show("ident count is , " + args.IdentifyResults.Count);
if (args.IdentifyResults.Count > 0)
{
foreach (var result in args.IdentifyResults)
{
bp.Features.Add(result.Feature);
}
gm.BufferCompleted += gm_BufferCompleted;
gm.Failed += GeometryService_Failed;
bp.Distances.Add(.001);
gm.BufferAsync(bp);
}
else
{
//clears combobox
IdentifyComboBox.Items.Clear();
IdentifyComboBox.UpdateLayout();
}
}
void gm_BufferCompleted(object sender, GraphicsEventArgs args)
{
GraphicsLayer layer = this.MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
Graphic IdentGraphic = new Graphic();
//Using this message box to show how many time this process runs
MessageBox.Show("bp.features is" + bp.Features.Count);
IdentGraphic = bp.Features[0];
ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
{
Geometry = IdentGraphic.Geometry,
MapExtent = MyMap.Extent,
SpatialReference = MyMap.SpatialReference,
Width = (int)MyMap.ActualWidth,
Height = (int)MyMap.ActualHeight,
LayerOption = LayerOption.all,
};
IdentifyTask identifyTask = new IdentifyTask ("https://myGISserver/ArcGIS/rest/services/" + MyMapService/MapServer");
identifyTask.ExecuteCompleted += IdentifyTask1_ExecuteCompleted;
identifyTask.Failed += IdentifyTask_Failed;
identifyTask.ExecuteAsync(identifyParams);
}
I suspect it's something to do with the foreach loop? And the reason I am using IdentGraphic = bp.Features[0]; is because if 2 features are selected, that means they are already overlapping and both will be populated in my combobox. The only issue I can see is 2 features selected at a high zoom level which do not intersect, but this likely will not be an issue.Thanks