문제

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;
            }
    }
도움이 되었습니까?

해결책

You can call Task.Delay .. and await the result:

await Task.Delay(5000);

You will need to make sure you mark your event as async too:

private async void RunTestButton_Click(object sender, RoutedEventArgs e)

다른 팁

PerformanceProgressbar is control, so you should put it on your page (use fade also).

But if you need to do some task on UI thread (do you really need it?) I recommend you to fade your page by showing semitransparent border over it, and show ProgressIndicator in statusbar. It's system object and will run even if app is frozen.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top