在 Windows 商店应用程序中调用服务时,ProgressBar 按钮不显示 [英] ProgressBar button doesn't show while service call in windows store app
问题描述
我想在进行服务调用时显示 ProgressBar.产品.xml
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
Product.xml.cs
loading.Visibility = Visibility.Visible; //loading start
getAllProductDetails(); //contain service call and bind data in list
loading.Visibility = Visibility.Collapsed; //loading finish
加载应该在getAllProductDetails()
"调用之前开始,并且应该在getAllProductDetails()
"完成后完成.
Loading should start before "getAllProductDetails()
" call and it should finish once "getAllProductDetails()
" finish.
如果我还使用了 await Task.Run(() => getAllProductDetails());
它会继续执行 "await Task.Run(() =>; getAllProductDetails());
".它必须等到getAllProductDetails()
"调用完成它的工作.
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?
推荐答案
更改您的 getAllProductDetails()
以返回 Task
而不是 void
Change your getAllProductDetails()
to return Task
instead of void
private async Task getAllProductDetails()
{
// Body
}
然后这样调用
loading.Visibility = Visibility.Visible; //loading start
await getAllProductDetails();
loading.Visibility = Visibility.Collapsed; //loading finish
如果任何异步函数返回void
,您就不能等待执行完成.
If any async function returns void
you can't wait for completion of execution.
这篇关于在 Windows 商店应用程序中调用服务时,ProgressBar 按钮不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!