title: BackgroundWorker is not able to prevent ProgressBar freezing when populating dynamic DataGrid
body: <p><strong>1-</strong> Copy and paste the following codes into <strong>MainWindow.xaml</strong> file.</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"&gt;
  &lt;Grid&gt;
      &lt;DataGrid x:Name="DataGrid1"/&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>2-</strong> Copy and paste the following codes into <strong>MainWindow.xaml.cs</strong> file.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.ComponentModel;
  using System.Threading;
  
  namespace WpfApplication1
  {
  
  public partial class MainWindow : Window
  {
      BackgroundWorker BackgroundWorker1 = new BackgroundWorker();
      BackgroundWorker BackgroundWorker2 = new BackgroundWorker();
      System.Data.DataTable DataTable1 = new System.Data.DataTable();
  
      public MainWindow()
      {
          InitializeComponent();
          BackgroundWorker1.DoWork += BackgroundWorker1_DoWork;
          BackgroundWorker2.DoWork += BackgroundWorker2_DoWork;
      }
  
      void Window_Loaded(object sender, RoutedEventArgs e)
      {
          BackgroundWorker1.RunWorkerAsync();
          BackgroundWorker2.RunWorkerAsync();
      }
  
      private void BackgroundWorker1_DoWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
      {
          Dispatcher.Invoke(() =&gt;
          {
              Window1 myWindow1 = new Window1();
              myWindow1.ShowDialog();
          });
      }
  
      private void BackgroundWorker2_DoWork(System.Object sender, System.ComponentModel.DoWorkEventArgs e)
      {
          for (int i = 1; i &lt;= 7; i++)
              DataTable1.Columns.Add();
          for (int i = 1; i &lt;= 1048576; i++)
              DataTable1.Rows.Add(i);
          Dispatcher.Invoke(() =&gt;
          {
              DataGrid1.ItemsSource = DataTable1.DefaultView;
          });
      }
  
  }
  }
  </code></pre>
  
  <p><strong>3-</strong> Create a new Window and named it as <strong>Window1</strong>.</p>
  
  <p><strong>4-</strong> Copy and paste the following codes into <strong>Window1.xaml</strong> file.</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="1000" ContentRendered="Window_ContentRendered"&gt;
  &lt;Grid&gt;
      &lt;ProgressBar x:Name="ProgressBar1" Height="25" Width="850"/&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>5-</strong> Copy and paste the following codes into <strong>Window1.xaml.cs</strong> file.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Shapes;
  
  namespace WpfApplication1
  {
  public partial class Window1 : Window
  {
      public Window1()
      {
          InitializeComponent();
      }
  
      private void Window_ContentRendered(object sender, EventArgs e)
      {
          ProgressBar1.IsIndeterminate = true;
      }
  }
  }
  </code></pre>
  
  <p><strong>6-</strong> When you run this project you will see that <strong>ProgressBar1</strong> is freezing for two or three seconds while the following line runs because of adding 1048576 rows to the DataGrid. (Huge rows)</p>
  
  <pre><code>DataGrid1.ItemsSource = DataTable1.DefaultView;
  </code></pre>
  
  <p>I dont want <strong>ProgressBar1</strong> is freezing.</p>
  
  <p>So why <strong>BackgroundWorker</strong> is not able to prevent <strong>ProgressBar</strong> freezing?</p>