Forum Xamarin.Forms

async Task.Run/Device.BeginInvokeOnMainThread issues

PhillipSzymanskiPhillipSzymanski USMember ✭✭
edited July 2016 in Xamarin.Forms


I'm working on a problem that I first described in this thread, but I think the problem has evolved enough that I should make a new post.

I have a ListView that when a user selects an item, and image in the item disappears and the image is replaced by an ActivityIndicator. The image disappears as planned, but the indicator doesn't appear until just before the next page appears. The following code is what I started with for the ItemSelected:

                        Row row = (Row)e.SelectedItem;
                        row.loading = true;
                        await Task.Yield();
                        await Navigation.PushAsync(new NextPage(row));

If I wrap the last line in a Task.Run, as below, I get "UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.":

await Task.Run( () => Navigation.PushAsync(new NextPage(row)));

I've also tried wrapping all of that in a Device.InvokeOnMainThread, but if I do nothing happens at all.

Best Answer


Sign In or Register to comment.