如何在不冻结 UI 的情况下暂停应用程序 [英] How to Pause an Application without Freezing the UI
本文介绍了如何在不冻结 UI 的情况下暂停应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的点击事件中,我想在一定时间内显示一个不确定的进度条,然后恢复应用程序.我遇到的问题是我无法显示进度条.有人可以帮忙吗?
On my click event I want to show an indeterminate progressbar for a certain amount of time, and then resume the application. The problem I am having is that I cannot get the progressbar to show. Could someone help with this?
private void RunTestButton_Click(object sender, RoutedEventArgs e)
{
if (testRunning == false)
{
testRunning = true;
//Set progress bar visibility
PerformanceProgressbar.Visibility = Visibility.Visible;
PerformanceProgressbar.IsIndeterminate = true;
//Tell the app to pause for 5 seconds so the user sees the progress bar
//Set progress bar visibility
PerformanceProgressbar.IsIndeterminate = false;
PerformanceProgressbar.Visibility = Visibility.Collapsed;
testRunning = false;
}
}
推荐答案
您可以拨打 Task.Delay .. 和 await
结果:
You can call Task.Delay .. and await
the result:
await Task.Delay(5000);
您还需要确保将您的活动标记为async
:
You will need to make sure you mark your event as async
too:
private async void RunTestButton_Click(object sender, RoutedEventArgs e)
这篇关于如何在不冻结 UI 的情况下暂停应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文