Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android.OS.NetworkOnMainThreadException: '' on RefreshCommand #81

Open
Alex-451 opened this issue Dec 31, 2020 · 0 comments
Open

Android.OS.NetworkOnMainThreadException: '' on RefreshCommand #81

Alex-451 opened this issue Dec 31, 2020 · 0 comments

Comments

@Alex-451
Copy link

I have the following code:

public ICommand RefreshCommand { get; }

public HomeViewModel()
{
     Title = "Test";
     Youtube = new List<Rank>();
     Task.Run(async () => await LoadRanks());
     RefreshCommand = new AsyncCommand(LoadRanks);
}
Task.Run(async () => await LoadRanks());

Runs through with out any issues, (before i added the Task.Run thing i got the same error i now get if the command gets called).
If i trigger the RefreshCommand by refreshing my CollectionView i get the error:
Android.OS.NetworkOnMainThreadException: ''

Method that the command runs:

async Task LoadRanks()
{
       var client = new RanksClient();

        Youtube = (await client.GetViewsScoreboardAsync(RankViewsPlatform.Youtube, Size.Small)).ToList();
        Instagram = (await client.GetLikesScoreboardAsync(RankLikesPlatform.Instagram, Size.Small)).ToList();
        TikTok = (await client.GetLikesScoreboardAsync(RankLikesPlatform.TikTok, Size.Small)).ToList();
        Twitter = (await client.GetLikesScoreboardAsync(RankLikesPlatform.Twitter, Size.Small)).ToList();
        Twitch = (await client.GetViewersScoreboardAsync(RankViewerPlatform.Twitch, Size.Small)).ToList();
}

If you guys have any idea how to solve this, please let me know.
https://user-images.githubusercontent.com/33844665/103391376-7d192e80-4b19-11eb-87a0-bf31875a5e2a.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant