Select to view content in your preferred language

cancel query task in flex

3292
15
01-04-2011 11:08 PM
ReenaSingh
Emerging Contributor
How to cancel the querying task of query task in the middle of query process and stop all query process.
Tags (2)
0 Kudos
15 Replies
ReenaSingh
Emerging Contributor
Please help me, i need it urgently ... 😞
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Reena,

   Just remove the event listener form the query task. So if you are doing some code like this:

queryTask.execute(query, new AsyncResponder(onResult, onFault));
//you need to change it to
queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);
queryTask.addEventListener(FaultEvent.FAULT, onFault);
queryTask.execute(query);
//That way you can use remove listener
queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);
0 Kudos
DasaPaddock
Esri Regular Contributor
0 Kudos
ReenaSingh
Emerging Contributor
Reena,

   Just remove the event listener form the query task. So if you are doing some code like this:

queryTask.execute(query, new AsyncResponder(onResult, onFault));
//you need to change it to
queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);
queryTask.addEventListener(FaultEvent.FAULT, onFault);
queryTask.execute(query);
//That way you can use remove listener
queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);


hello,
But I am not using queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);
queryTask.addEventListener(FaultEvent.FAULT, onFault);
My code is :
queryTask.executeForIds(query,new AsyncResponder(onResult,onFault,token))
Now I want to stop this task in between.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Reena,
queryTask.executeForIds(query,new AsyncResponder(onResult,onFault,token))
//you need to change it to
queryTask.addEventListener(QueryEvent.EXECUTE_FOR_IDS_COMPLETE, onResult);
queryTask.addEventListener(FaultEvent.FAULT, onFault);
queryTask.executeForIds(query);
//That way you can use remove listener
queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);
0 Kudos
ReenaSingh
Emerging Contributor
Reena, 
queryTask.executeForIds(query,new AsyncResponder(onResult,onFault,token))
//you need to change it to
queryTask.addEventListener(QueryEvent.EXECUTE_FOR_IDS_COMPLETE, onResult);
queryTask.addEventListener(FaultEvent.FAULT, onFault);
queryTask.executeForIds(query);
//That way you can use remove listener
queryTask.removeEventListener(QueryEvent.EXECUTE_COMPLETE, onResult);



Hello,

Then how to pass token as object through this.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Reena,

   The only way that I know of to pass a token object to an event listener is to create an inline function and that defeats the ability to remove the event listener. If you really need that token you need to find away to create a var that can hold the object that you can access from the onResult function.
0 Kudos
DasaPaddock
Esri Regular Contributor
Another approach could be to keep using responders but create a class member like "private var requestCancelled:Boolean" that you check in your onResult().
0 Kudos
ReenaSingh
Emerging Contributor
Reena,

   The only way that I know of to pass a token object to an event listener is to create an inline function and that defeats the ability to remove the event listener. If you really need that token you need to find away to create a var that can hold the object that you can access from the onResult function.


Hi,

Actually i have some set of queries which run in loops, after execution of these queries, there are some other queries which needs to be fired.
Then I want to stop all these queries, for which I have used removeEventlisteners but I am not able to stop those which are already got excuted in loop.
For this i have even used even Boolean to check the condition for stopping, but the queries which are already excuted; am not able to stop them. Is there any property in the GIS Flex api to stop executions of all queries at a time.
0 Kudos