Select to view content in your preferred language

BufferCompleted running too many times

958
4
04-05-2011 10:56 AM
TylerMunn
Emerging Contributor
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
0 Kudos
4 Replies
by Anonymous User
Not applicable
You are adding a new event handler each time IdentifyTask2_ExecuteCompleted is executed. Thats why it fires +1 each consective iteration.
0 Kudos
TylerMunn
Emerging Contributor
Thanks, but how do I go about using the BufferCompleted event handler when IdentifyTask2_ExecuteCompleted is executed, without adding +1 each time? It needs to fall within IdentifyTask2_ExecuteCompleted each time the identify task has been run, does it not?
0 Kudos
JenniferNery
Esri Regular Contributor
You can wire up to these events one time when you first created GeometryService (gm). Only the BufferParameters need to change when IdentifyTask is completed, which you use to execute BufferAsync().
0 Kudos
TylerMunn
Emerging Contributor
Got it! Thanks.
0 Kudos