Need help with async requests..

Topics: Developer Forum
Jan 12, 2011 at 5:37 PM

Been using your library for a long time and love it but am lost when it comes to async requests in general.. Do you have an example? Would love to see one using interestingnessgetlistasync if possible. Thank you for your wonderful work

 

Jesse,

Coordinator
Jan 18, 2011 at 9:48 AM

Async methods go something like this:

Flickr f = new Flickr(ApiKey, SharedSecret, AuthToken);

f.PhotosetsGetListAsync(r =>
  {
      if (r.HasError)
      {
          // check r.Error to see what the error is.
      }
      else
     {
         // r.Result is the actual result.
         PhotosetCollection photosets = r.Result;
     }
  });


r is an FlickrResult<T> where T will be the actual result for whatever you are calling (in this instance FlickrResult<PhotosetCollection>).

If you didn't want to use lambda expressions you could create a method that took the FlickrResult<T> as an argument like so:

private void PhotosetGetListCallback(FlickrResult<PhotosetCollection> r)
{
  // check r.Error and r.Result in here.
}

// and then call as follows:

var action = new Action<FlickrResult<PhotosetCollection>>(PhotosetGetListCallback);

f.PhotosetsGetListAsync(action);

Sorry for the delay in replying. Hope that helps.

Sam

May 1, 2012 at 12:00 AM

Hi.. sorry to barge in here but it's kind of related... is there a way to cancel an async request once it has fired off... for example, you have a bunch of async calls to get supporting information on a photo when being displayed, but then you click to the next photo... seems to hang until all the calls have returned, then goes to the next photo....  just curious..

Coordinator
May 1, 2012 at 10:20 AM

There isn't an way to cancel a request unfortunately. No call should really be taking more than a few milliseconds.

I don't understand why it is hanging and waiting for all calls to return - this is kinda of the opposite I would expect to see for asynchronous calls. perhaps you could show us some of your code and we might be able to help.