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

Where to make the async call

$
0
0

I'm creating a X.F application. I want to make an async requesting using the httpclient client class. I'm not quite sure where that call should go at. In the examples of X.F that I have seen, all of the setup occurs in the initialization of a class. I am guessing that there is a better place to make the request. In iOS & Android, this is done by marking one of the overridden events with the async keyword. Is there a recommended place to do something similar in X.F?

public class MainScreen : ContentPage  
{  
    string[] golfers;  
    public MainScreen ()
    {
        var listView = new ListView(){ RowHeight = 40 };
        Content = new StackLayout(){
            VerticalOptions = LayoutOptions.FillAndExpand,
            Children = { listView },
        };
        listView.ItemTapped += HandleItemTapped;
        golfers = await class.MethodAsync(SomeUserIdValue);  <-- Where does this method need to go. The initializer is not a good place in my mind
        listView.ItemsSource = golfers;

    }

}

Viewing all articles
Browse latest Browse all 58056

Trending Articles