title: wpf app crashes when BackgroundWorker is used
body: <p>my view model creates a BackgroundWorker in its constructor. BackgroundWorker updates the model's properties from its DoWork event handler. The code below is a contrived example (ViewModelBase is taken almost verbatim from the MVVM paper).</p>
  
  <pre><code>
  public class MyViewModel : ViewModelBase
  {
      public int MyProperty
      {
          get
          {
              return this.my_property;
          }
          private set
          {
              if (this.my_property != value)
              {
                  this.my_property = value;
                  this.OnPropertyChanged("MyProperty");
              }
          }
      }
  
      public MyViewModel()
      {
          this.worker = new BackgroundWorker();
          this.worker.DoWork += (s, e) => { this.MyProperty = 1; };
          this.worker.RunWorkerAsync();
      }
  }
  </code></pre>
  
  <p>my view is bound to this view model:</p>
  
  <pre><code>
  public partial class MyPage : Page
  {
      public MyPage()
      {
          InitializeComponent();
          this.DataContext = new MyViewModel();
          }
  }
  </code></pre>
  
  <p>the problem is that my application crashes intermittently when my page is displayed. this definitely has something to do with the worker thread and data binding in XAML. it seems that if i start the worker from inside the Loaded event handler for the page, the problem goes away but since it is hard to reproduce consistently, i am not sure whether this is the right fix.</p>
  
  <p>does any one have any suggestions or ideas what might be the exact cause?</p>
  
  <p>EDIT: i only can reproduce it if i run it without a debugger. and the error in the system log is InvalidOperationException thrown from ShowDialog, which is not much help. under the debugger it runs fine.</p>
  
  <p>thanks for any help
  konstantin</p>