Select to view content in your preferred language

QueryTask question

1441
8
03-28-2011 07:21 AM
ThaoNguyen
Emerging Contributor
Is there a way I can pass in my own parameters to QueryTask?
I can have 2 or more QueryTask run asynchronously, and the completed event handler are invoked after each QueryTask is done.  I want to pass in a parameter to recognize which QueryTask I'm running.  Or is there a flag or property that I can detect?

Thanks!
0 Kudos
8 Replies
DaveTimmins
Deactivated User
You can pass in a value for the userToken when you invoke ExecuteAsync. See the reference for details http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Quer...
0 Kudos
ThaoNguyen
Emerging Contributor
You can pass in a value for the userToken when you invoke ExecuteAsync. See the reference for details http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Quer...


Actually, I want to retrieve the value when the completed event handler is called so that I can use this value for something else.  I found QueryTask.Token helps me achieve this goal.
Can I retrieve userToken in completed event handler?
0 Kudos
JenniferNery
Esri Regular Contributor
Yes, you will have access to UserToken in the Completed event. See post# 4 in this thread http://forums.arcgis.com/threads/19810-showing-related-records-in-maptips
0 Kudos
ThaoNguyen
Emerging Contributor
Yes, you will have access to UserToken in the Completed event. See post# 4 in this thread http://forums.arcgis.com/threads/19810-showing-related-records-in-maptips


I'm using QueryTask.  I've been adding new attributes to graphic and have no problem with that.  My question is different.  For each QueryTask, before it is executed, I want to set some values to QueryTask so that I can retrieve when the task is completed.  Just imagine QueryTask as a car. Before it runs, I put some cargos in that car, when it reaches my destination, I want to get my cargos back.
It's like writing a jsp page, you can pass in parameters in url such as: http://www.mypage.com?myParam1=test1&myParam2=test2.
myParamx are what I mean, I want to pass along the parameters for my use later for each QueryTask.
Anyway, I think QueryTask.Token works for me at this point.  Not really sure if it is safe to use for my case :).  I hope it is OK.  I don't see any reason for "unsafe".

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
Yes, this is possible with UserToken
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters["param1"] = 1;
parameters["param2"] = "one";
QueryTask qt = new QueryTask();
Query q = new Query();
qt.ExecuteCompleted += (s, e) =>
{
 var myParams = e.UserState as IDictionary;
 var param1 = (int)myParams["param1"];
 var param2 = (string)myParams["param2"];
};
qt.ExecuteAsync(q, parameters);
0 Kudos
ThaoNguyen
Emerging Contributor
Yes, this is possible with UserToken
IDictionary<string, object> parameters = new Dictionary<string, object>();
parameters["param1"] = 1;
parameters["param2"] = "one";
QueryTask qt = new QueryTask();
Query q = new Query();
qt.ExecuteCompleted += (s, e) =>
{
 var myParams = e.UserState as IDictionary;
 var param1 = (int)myParams["param1"];
 var param2 = (string)myParams["param2"];
};
qt.ExecuteAsync(q, parameters);


That's great!!! It is what I'm looking for.  Thanks!
0 Kudos
GeorgePan
Occasional Contributor
Yes, you will have access to UserToken in the Completed event. See post# 4 in this thread http://forums.arcgis.com/threads/19810-showing-related-records-in-maptips


Do you have any issues to use QueryTask.Token = "Token", I got a token with 120 minutes life time from the secured ArcGIS Server 10 web service, and it works well using http://......./?query/token=taokenstring on IE, but run it from Silverlight C# code, it always shows me the error: SystemSecurityException. Is that an ESRI issue / bug?

Thanks,

George
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Is there a way I can pass in my own parameters to QueryTask?
I can have 2 or more QueryTask run asynchronously, and the completed event handler are invoked after each QueryTask is done. I want to pass in a parameter to recognize which QueryTask I'm running. Or is there a flag or property that I can detect?

Thanks!

As Dave mentionned, you can set a userToken when you invoke ExecuteAsync.
Then when the query has completed, we'll get this userToken as 'UserState' property of the returned QueryEventArgs.
0 Kudos