Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Navigating from Within an async task doesn't seem to work?

$
0
0

So I have a task in a RelayCommand in my VM like so:

Task.Factory.StartNew(async () => 
{
         var picture = await op.ImportPhoto();
         try
         {
                 ViewOperations.Navigate(new MyPage());
         }
         catch (Exception ex)
         {
         }
});

ViewOperations is a property on this VM which is an interface to allow me to Call navigate from the view model and navigate to the next page

so the Navigate method in my code behind of the view looks like this:

    public void Navigate(Page page)
    {
       Navigation.PushAsync(page);
    }

but nothing happens on clicking the button. If I make the Navigate method async and Await Navigation.PushAsync like so:

    public async void Navigate(Page page)
    {
       await Navigation.PushAsync(page);
    }

I get invalid cross-thread exception. Whats happening here? Am I doing something incorrect?


Viewing all articles
Browse latest Browse all 58056

Trending Articles