问题
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