async / await call happens but table not populated on page

MichaelStark.5935MichaelStark.5935 USUniversity, Developer Group Leader ✭✭

I call a function with await to populate a tablesource. The function runs but the visible table is not populated visually. Do I neeed to move the call outside the ViewDidLoad event?
Note: the async function makes a call to Azure Mobile Services. In debug it runs and populates the list.

    public async override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        Title = "PodCasts";

        TableView = new UITableView (Rectangle.Empty, UITableViewStyle.Plain); // Grouped or Plain

        await RefreshTodoItems ();

    }
    private async Task RefreshTodoItems()
    {
        podcastlist = new List<PodcastItem> ();
        MobileServiceInvalidOperationException exception = null;
        try
        {
            AppDelegate.podcasts = await podcastTable
                .ToCollectionAsync();
        }
        catch (MobileServiceInvalidOperationException e)
        {
            exception = e;
        }

        if (exception != null)
        {
            //await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
        }
        else
        {
            foreach (podcast pc in AppDelegate.podcasts) {
                podcastlist.Add (new PodcastItem {
                    Title = pc.Title,
                    Speaker = pc.PodcastName,
                    Location = pc.MediaURL,

                    Begins = new DateTime (2013, 4, 14, 9, 0, 0)
                });

            }
            TableView.Source = new PodcastsTableSource (podcastlist, this);
        }
    }

Posts

Sign In or Register to comment.