1

I am trying to perform a query on an ArcGIS for server mapserver. Running a query that returns a small number of records is fine but, if I run a query that returns a lot of records, I receive this error:

The CLR has been unable to transition from COM context 0x10e1080 to COM context 0x10e0f58 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Here is my C# code:

private void RunQuery()
        {
            _attributeQueryGraphicsLayer.Graphics.Clear();

            QueryTask queryTask = new QueryTask("http://10.1.2.103:6080/arcgis/rest/services/Calvert_City_Test/MapServer/2");
            queryTask.ExecuteCompleted += GeneralQueryTask_ExecuteCompleted;
            queryTask.Failed += GeneralQueryTask_Failed;

            var dirty = DateTime.UtcNow;
            Query query = new Query();
            query.OutFields.Add("*");
            query.ReturnGeometry = true;
            query.Where = "CIS_METR LIKE '%" + QueryParametersTextbox.Text + "%' OR COMMENTS LIKE '%" + QueryParametersTextbox.Text + "%'";
            query.OutSpatialReference = MyMap.SpatialReference;

            queryTask.ExecuteAsync(query);
        }

        // Draw results when query is complete
        private void GeneralQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            // Clear previous results
            QueryDataGrid.Visibility = Visibility.Visible;
            GraphicsLayer graphicsLayer = MyMap.Layers["QueryResults"] as GraphicsLayer;
            graphicsLayer.ClearGraphics();

            // Check for new results 
            FeatureSet featureSet = args.FeatureSet;
            if (featureSet.Features.Count > 0)
            {
                // Add results to map
                foreach (Graphic resultFeature in featureSet.Features)
                {
                    //resultFeature.Symbol = ResultsFillSymbol;
                    graphicsLayer.Graphics.Add(resultFeature);
                }
            }
            else
            {
                MessageBox.Show("No features found");
            }
        }

        // Notify when query fails
        private void GeneralQueryTask_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Query failed: " + args.Error);
        }
          #endregion

Note: Turning off this exception is not an option. It will just cause my application to freeze.

Any help would be appreciated. If you need any more information, please let me know.

JLott
  • 1,818
  • 3
  • 35
  • 56
  • 1
    seems it's taking too long to come back, perhaps you can try increasing the time out, or querying in chunks (batches) then aggregate them together when done – Jason Feb 27 '14 at 21:00
  • There's a very similar question, with a good answer here: http://stackoverflow.com/questions/2797677/contextswitchdeadlock-was-detected-error-in-c-sharp?rq=1 – Daniel James Bryars Feb 27 '14 at 21:03
  • Is it a UI app? What do you do after `RunQuery`? Do you use any kind of blocking wait, like `WaitHandle.WaitOne`? – noseratio Feb 27 '14 at 22:19
  • Yes it is just a normal desktop C# application. After RunQuery() it will display the results in a grid. And no I do not. – JLott Feb 27 '14 at 22:23

0 Answers0