I want to update the value of a progress bar in a WPF form to indicate the progress of a set of tasks.

The tasks are performed by an API provided in a dll. The API provides information about the total number of tasks and the number of tasks completed.

I have binded the value of the progress bar with a property in my main class, but I cannot display the progress during the execution of the tasks, just the progress at 0% and at 100%.

**MyForm.xaml.cs**

```cs
   public partial class MyForm : Page, INotifyPropertyChanged
   {
      public int PercentageOfTasksCompleted
      {
         get
         {
            int percentage_completed = 100 * externalAPI.NumberOfTasksCompleted / externalAPI.TotalNumberOfTasks;

            return percentage_completed;
         }
         set
         {
            if (PropertyChanged != null)
            {
               PropertyChanged(this, new PropertyChangedEventArgs("PercentageOfTasksCompleted"));
            }
         }
      }

      private async void ButtonExecuteTasks_ClickAsync(object sender, RoutedEventArgs e)
      {
         await Task.Run(() =>
         {
            externalAPI.ExecuteTasks();
         });
      }
   }

```

**MyForm.xaml**

```xml
<Grid HorizontalAlignment="Left" VerticalAlignment="Bottom" Height="20" Width="200">
    <ProgressBar x:Name="myProgressBar" Value="{Binding PercentageOfTasksCompleted, Mode=OneWay}" Minimum="0" Maximum="100"/>
    <TextBlock Text="{Binding ElementName=myProgressBar, Path=Value, StringFormat={}{0:0}%}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>

```

As for reproducing the scenario I think that the external API class could look like this:

**ExternalAPI.cs**

```cs
   public class ExternalAPI
   {
      public int TotalNumberOfTasks {get; private set;}
      public int NumberOfTasksCompleted {get; private set;}

      public void ExecuteTasks() {
         for (int i=1; i<=TotalNumberOfTasks; i++)
         {
            Thread.Sleep(100);
            NumberOfTasksCompleted = i;
         }
      }
   }

```

What would be the best approach to have the progress bar value updated during the execution of the tasks? Thanks!