This project has moved and is read-only. For the latest updates, please go here.

WP8 await on async void methods?

Aug 5, 2013 at 2:20 AM
Edited Aug 5, 2013 at 2:25 AM
Is it possible to await the result of the async methods? I tried await Task.Run but it doesn't seem to work.

For example
PhotoCollection pc = new PhotoCollection();
        await Task.Run(() => f.PeopleGetPhotosAsync(p.UserId, options, page, count, (x) =>
            if (x.Error == null)
                pc = x.Result;
        return pc;
pc returns empty, but x.Result is valid so my code does not appear to be waiting for the call to complete. Sorry, I am new to async and tasks.
Aug 5, 2013 at 1:48 PM
I think I would do something like this:
var pc = await Task<PhotoCollection>.Run(() =>
    var t = new TaskCompletionSource<PhotoCollection>();

    f.PeopleGetPhotosAsync(p.UserId, options, page, count, r => { 

    return t.Task;
I haven't tested this, but it might work.
Aug 6, 2013 at 5:50 PM
Thank you Sam, I will try this later!