ProgressBar button doesn't show while service call in windows store app

ε祈祈猫儿з 提交于 2020-01-05 17:30:11

问题


I want to show ProgressBar when service call made. Product.xml

<ProgressBar Name="loading1" Visibility="Collapsed" IsIndeterminate="True" HorizontalAlignment="Left" Height="50" Width="535" VerticalAlignment="Center" Background="White" Grid.Row="1" Margin="0,311,0,310"/>

Product.xml.cs

loading.Visibility = Visibility.Visible;  //loading start
getAllProductDetails();   //contain service call and bind data in list
loading.Visibility = Visibility.Collapsed;  //loading finish

Loading should start before "getAllProductDetails()" call and it should finish once "getAllProductDetails()" finish.

if I have also used await Task.Run(() => getAllProductDetails()); it keep execution of next line of "await Task.Run(() => getAllProductDetails());". It must wait until "getAllProductDetails()" call complete it's job.

Can anybody suggest me what I am missing here?


回答1:


Change your getAllProductDetails() to return Task instead of void

private async Task getAllProductDetails()
{
    // Body
}

And then call like this

loading.Visibility = Visibility.Visible;  //loading start
await getAllProductDetails();
loading.Visibility = Visibility.Collapsed;  //loading finish

If any async function returns void you can't wait for completion of execution.



来源:https://stackoverflow.com/questions/36597526/progressbar-button-doesnt-show-while-service-call-in-windows-store-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!