Cancel PhotosGetSizesAsync?

Topics: Developer Forum
May 7, 2014 at 6:15 PM
Edited May 7, 2014 at 6:16 PM
Hi! has been amazing but I need a way to cancel this block of code with a Cancellation token. How do I do this?
I already have a Cancellation Token Source which is set in the class, but I do not know how to cancel the awaiting of the Flickr task.
var t = new TaskCompletionSource<FlickrResult<SizeCollection>>();
var flickr = new Flickr("censored", "censored");
flickr.PhotosGetSizesAsync(photoToken, s => t.TrySetResult(s));
FlickrResult<SizeCollection> flickrImages = await t.Task;
At times, 10 of the "await t.Task" might run, and the app will "hang" until they are done waiting for the result and the task completes.
May 8, 2014 at 3:18 PM
In order to support cancellation my tasks would have to be checking if you had called Cancel on the cancellation token, something I'm not doing. I'm also not using Tasks all the way down the stack, but simply using a delegate to perform a callback.

Try looking at the next version of the code:

If you are using .Net 4.5 then there is a Task based library in there that uses tasks all the way down :) Might be better fit.
May 8, 2014 at 3:52 PM
I am developing for Windows Phone 8 so I guess I am SOL in that department.
I found the FlickrNet-Experimental had a portable library, but as far as I could see, no way to reference a cancellation token there yet.