'C# why does this reload method block the UI for a visible second

I have a function that makes a call to an API, and then binds the data to the view (along with a lot of local calculations in between.)

In short, this method looks like this:

        private async Task LoadMoreAds()
        {
            Task.Run(async () =>
            {

                await ...random api then
                ... do something with the results then 
                ... bind the views 

            });
        }

This method is called from UI event handler:

     private async void listview_allAds_FlowItemAppearing(object sender, ItemVisibilityEventArgs e)
{
            TinyAd current = e.Item as TinyAd;
             if (current == contentOfListView[contentOfListView.Count - 2])
                {
                    if (!isCurrentlyLoading)
                        await LoadMoreAds();     
                 }        
            }
    
}

I think I am doing all my async and awaits correctly.

But still i am seeing a slight hang on UI reload when the user scrolls fast- Also the framerate is not at 60, rather at avg of 30.

Is there something I can optimize?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source