When using the SearchAsync() of BingSearchProvider for concurrent calls I'm facing a problem where in the responses for all the calls has the same result location and user data. This is the code that I'm using to make the call.
if
(searchProvider != null)
{
SearchRequest request = new SearchRequest();
request.Culture =
CultureInfo.CurrentCulture;
request.Query = address;
request.UserData = userData
as object;
this.searchProvider.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(searchProvider_SearchCompleted);
this.searchProvider.SearchAsync(request);
}
The above part will be called multiple times even before the previous SearchAsync() function returned a result.
void searchProvider_SearchCompleted(object sender, SearchCompletedEventArgs e)
{
SearchResponse response = e.Response;
Location
locn = new Location();
if (response.ResultSets[0].Results.Count > 0)
{
foreach (SearchResultBase result in response.ResultSets[0].Results)
{
locn = result.LocationData.Locations[0];
}
}
if (response.ResultSets[0].SearchRegion != null)
{
if (response.ResultSets[0].SearchRegion.GeocodeLocation.Address != null
&& response.ResultSets[0].SearchRegion.GeocodeLocation.Locations.Count > 0)
{
locn = response.ResultSets[0].SearchRegion.GeocodeLocation.Locations.First();
locn.Description = address;
}
}
}
MessageBox
.Show("RequestUserData : " + e.Response.RequestUserData.ToString() + "\nLocation : " + locn.Latitude + "," + locn.Longitude);
}
Is there any thing that I'm missing out in this? Please help me overcome this problem.
I'm using Telerik RadControls for Silverlight 4 Version 2010_2_0924.
Thanks in Advance,
Senthil