[英]Changing visibility doesn't work on C# windows phone 8
I'm trying to display a progessbar during some work but the visibility doesn't change... 我想在一些工作中展示一个progessbar但是能见度不会改变......
private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
{
progressBar.Visibility = System.Windows.Visibility.Visible;
DoWork();//quite long (4-5 seconds)
progressBar.Visibility = System.Windows.Visibility.Collapsed;
}
Is there a resfreh method or something like that? 有没有resfreh方法或类似的东西? Am I doing something wrong?
难道我做错了什么?
You are executing DoWork()
in the UI thread, blocking it for 4 to 5 seconds. 您正在UI线程中执行
DoWork()
,将其阻止4到5秒。 This is why you are unable to see the progress bar. 这就是您无法看到进度条的原因。
Consider to call DoWork in a separate thread: 考虑在单独的线程中调用DoWork:
private async void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
{
progressBar.Visibility = System.Windows.Visibility.Visible;
await Task.Run(()=> DoWork()); //quite long (4-5 seconds)
progressBar.Visibility = System.Windows.Visibility.Collapsed;
}
Asynchronous Programming For Windows Phone 8 Windows Phone 8的异步编程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.