Canceling queryTask

4636
11
07-27-2011 05:22 AM
Labels (1)
ThaoNguyen
New Contributor II
Hi,
Is there a document on how to cancel an excuting QueryTask properly?
I know that there is method CancelAsync(), but I want to know more if additional steps need to be done to have this done properly.

Thanks!
0 Kudos
11 Replies
ThaoNguyen
New Contributor II
Hi,
Is there a document on how to cancel an excuting QueryTask properly?
I know that there is method CancelAsync(), but I want to know more if additional steps need to be done to have this done properly.

Thanks!


I found the following post which is what I'm looking for.  However, does that mean that the query is still running on the back end?  It is not really stopped?  Is there a way to really stop it?

http://forums.arcgis.com/threads/20473-cancel-query-task-in-flex

We have a hanging problem when the query is still running.  Our application allows users to add more than 1 map.  In one test case, our map query result is supposed to be big, and it takes long long time.  After I try to cancel by just unregistering the events as suggested in the post, then add another map, the application just hangs.  So, I think that the running queryTask causes this problem and looks like we cannot stop it??  Please help!
0 Kudos
JenniferNery
Esri Regular Contributor
You can call the following method: http://help.arcgis.com/en/webapi/wpf/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.TaskBase~Can...


if (queryTask.IsBusy)
  queryTask.CancelAsync();
queryTask.ExecuteAsync(query);
0 Kudos
ThaoNguyen
New Contributor II
You can call the following method: http://help.arcgis.com/en/webapi/wpf/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.TaskBase~Can...


if (queryTask.IsBusy)
  queryTask.CancelAsync();
queryTask.ExecuteAsync(query);


Yes, I tried that first but it didn't help :(.
I found that, while the QueryTask is still running, and I try to add another map, my code has the following code to get map json result.  This execution takes longer until it is timed out.  While it is being processed, my application hangs until it is timed out and done.  I don't know why the QueryTask causes the line not be able to executed.  If QueryTask is not running, it only takes few seconds.

var client = new System.Net.WebClient();
StreamReader reader = new StreamReader(clien.openRead(<my map URL here>));
0 Kudos
RyanCoodey
Regular Contributor
Hey Thao, thanks for the post... did you ever get this resolved?  I seem to be having the same issue. 

We have WPF maps embedded in another application and multiple maps can be opened.  Most the time everything is fine, but once in awhile the application will just hang for one to two minutes.  It seems that it is hanging at a simple QueryTask (which is called on each map load) which usually returns in a split second.  It is hard to reproduce, so haven�??t pinpointed it exactly, but it seems to always be when a second map has been up or loading.

Both maps are calling a static method which creates a new QueryTask and then executes it inline (because I need the method to return results).  I don't see any errors in the AGS logs either.  I haven�??t noticed this error until recently upgrading from the 2.2 API to the 2.4, but I have changed other code that might just be exposing this error more now.

Thanks for any info!
0 Kudos
RyanCoodey
Regular Contributor
Update*

Setup a little test, and I would expect this code to work, but the second QueryTask times out just about all the time:

Query query = new Query();
//Setup query here...

QueryTask queryTask = new QueryTask(Url);
queryTask.ExecuteAsync(query);

QueryTask queryTask2 = new QueryTask(Url);
queryTask2.Execute(query);  //This one always times out after a minute or so


Since it is a new QueryTask object, I would expect the second task to execute fine.  If I comment out the first, then it works... I tried setting DisableClientCaching both true and false for both, that doesn't seem to help. Running AGS 10.0 SP2, think 10.1 might resolve this in anyway, or is it purely a client issue?

Thanks a lot for any ideas!
0 Kudos
JenniferNery
Esri Regular Contributor
I could not reproduce with the following code. Does query need to be complicated? Do both QueryTask point to the same service URL? This prints to OutputWindow that both QueryTask executes fine. Have you tried sampleserver or is it service-specific perhaps? Please tweak the following code, I would like to reproduce and see if we can fix the bug. Thanks.

                        var query = new Query() { Where = "1=1", ReturnGeometry = true };
   query.OutFields.Add("*");
   var firstQT = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer/0");
   firstQT.Failed += (s, e) =>
   {
    System.Diagnostics.Debug.WriteLine("firstQT.Failed");
   };
   firstQT.ExecuteCompleted += (s, e) =>
   {
    System.Diagnostics.Debug.WriteLine("firstQT.ExecuteCompleted");
   };
   var secondQT = new QueryTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/EarthquakesFromLastSevenDays/MapServer/0");
   secondQT.Failed += (s, e) =>
   {
    System.Diagnostics.Debug.WriteLine("secondQT.Failed");
   };
   secondQT.ExecuteCompleted += (s, e) =>
   {
    System.Diagnostics.Debug.WriteLine("secondQT.ExecuteCompleted");
   };
   firstQT.ExecuteAsync(query);
   secondQT.ExecuteAsync(query);
0 Kudos
RyanCoodey
Regular Contributor
Thanks a lot for looking into this Jennifer!

Does query need to be complicated?

Query I am using is not really complex, "1=1 ORDER BY " + dateField + " DESC".  Maybe the order by is a problem? I tried adding this same thing on the datetime field from the sampleserver and it throws "Unable to complete  operation".  I don't get that with mine though.

Do both QueryTask point to the same service URL?

Yes, both point the same.

Have you tried sampleserver or is it service-specific perhaps?

Tried the sampleserver like you had setup, does not seem to have the problem.

Currently I cannot reproduce this issue with our server either though... not sure why.  It was happening 90% of the time before.  Maybe it depends on the server load?  We allow up to 4 instances for this service. I had restructured our code to work only with an async call, so if this does happen it doesn't lock up the app, but tried switching back to the non-async call and it is working fine too.  Hope that helps a little bit, but now that I can't reproduce it, I'm not sure... hate those temperamental issues.

Thanks again!
0 Kudos
JenniferNery
Esri Regular Contributor
No problem. Thanks for the follow-up. If the issue persists again, maybe you can submit to support and/or post also on server forum, or share the service so we can try here too.
0 Kudos
michaelcasallo
New Contributor

would anyone know, is the querytask used only for http URLs or can I use it with a https URL?

0 Kudos