سؤال

I am using the ExecuteQueryAsync on multiple lists to fill data into a List<ListItemCollection>. Once all the responses are received, I bind the data onto my Silverlight Application.

ExecuteQueryAsync could ideally go into success or failure. I basically keep track of the total number responses received on both Success and Failure and once the count received matches with the total requests. I show a wait icon till all the responses are received and the data is bound to the application. Now the problem is that, for example, I make 12 requests, I receive only 10 or 11 responses back. I don't seem to understand why I dont receive the response for the last few requests. I neither goes to success not to failure.

Is someone facing this issue? Could you help me understand what is causing this issue and why the response is neither received as a success nor a failure. If I perform the same operation, it works. This issue keeps happening every now and then and I am not sure how to fix this issue.

var requestCount = 0;
var responseCount = 0;
List<ListItemCollection>() bindingData;
public function getData(){
   showWaitIcon();
   //Some Code here to form the CAML query
   bindingData = new List<ListItemCollection>();
   for(int i=0; i<10; i++){
      //Some Code here to create the Client Context to query each Document Library or List
      clientContext.RequestTimeout = -1;
      clientContext.Load(clientContext.Web);
      ListItemCollection _lstItems;
      clientContext.Load(_lstItems);
      clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
      requestCount++;
   }
}

private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
     responseCount++;
     this.Dispatcher.BeginInvoke(BindData);
}

private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
     responseCount++;
     this.Dispatcher.BeginInvoke(BindData);
}

private function BindData(){
    if(requestCount == responseCount() {
        hideWaitIcon();
        bindToSilverlightView(bindingData);
    }
}
هل كانت مفيدة؟

المحلول

The most probable cause I can think of, without looking through your code, is that you have a synchronization issue, that is, two or more of your requests are receiving the result at nearly the exact same time and trying to modify the variable where you keep track of the number of answered requests. You may need to use a "lock" or similar structure to make sure that block of code is not accessed by two threads at once.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top