0

I am trying to use the ProgressBarCircular from Xceed.WpfToolKit without success.

I followed the following question to help me make it work : C# WPF Indeterminate progress bar

so my code now looks like that :

private async void ConvertButton_Click(object sender, RoutedEventArgs e)
{
    this.ProgressBar.IsIndeterminate = true;
    await DoWorkAsync();
    this.ProgressBar.IsIndeterminate = false;   
}


private async Task DoWorkAsync()
{
    await Task.Run(() =>
    {
        this.Dispatcher.Invoke(() =>
        {
           // do my work (using my WPF mainWindow Fields)
        });
    });
}

However I keep having the Exception :

Object reference not set to an instance of an object

on the line

this.ProgressBar.IsIndeterminate = false;

Seeing how I declare ProgressBar in my xaml file and the line

this.ProgressBar.IsIndeterminate = true;

works perfectly fine (and if IsIndeterminate = false is declared before it is set to true, I have no problem either), I don't understand what might cause this exception.

Solution

It turned out that I was using some others UI's value (like TextBox.Text) in my DoWorkAsync functions and I was not using Thread.Sleep(1000) in the function as well, so ProgressBar.IsIndeterminate did not have time to change its value twice and thus threw the exception

NicolasR
  • 685
  • 1
  • 10
  • 15
  • 1
    I guess something happens in the setter of the *IsIndeterminate* property (although, there is still a remote chance that *this.ProgressBar* itself somehow became `null`). Look at the exception stacktrace... For more information of how to troubleshoot NullReferenceExceptions, see here: [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) –  Jun 28 '17 at 10:24
  • Which control are you referring to? Please provide a link to whatever "ProgressBarCircular" control you are using. Does your code if you are using the built-in ProgressBar control? – mm8 Jun 28 '17 at 10:41

0 Answers0