Question

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;
            }
    }
Était-ce utile?

La solution

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)

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top