title: switching to dispatcher thread in WPF
body: <p>This is the follow up to this <a href="https://stackoverflow.com/questions/11703807/calling-method-indefinitely">Question</a>.</p>
  
  <p>I have to update a ObservableCollection from a different Thread. I tried it with the following Code:</p>
  
  <pre><code>            Thread t = new Thread(  ()=&gt;
           {
               while(true)
               {
  
                   if (ErrorDetection.ErrorDetectionIO.doErrorDetection() == 1)
                   {
                       dataLine = ErrorDetection.ErrorDetectionIO.getDataLine();
  
                       if (mainWindow != null)
                       {
                           ISynchronizeInvoke target = mainWindow; // mainWindow needs to be an WindowsForm?
                           target.Invoke(
                              (Action)(() =&gt;
                               {
                                  mainWindow.setNewDataLine(dataLine);
                               }
                               ), null);
                       }
  
                   }
               }
  
           }  );
  
           t.IsBackground = true;
           t.Start();
  </code></pre>
  
  <p>ErrorDetectionIO.doErrorDetection() is in a c++/cli .dll and calls native c Code.</p>
  
  <p>setNewDataLine is on the mainWindow and adds a Line to the Observable Collection.</p>
  
  <p>If its called from a different Thread it causes an exception:
  "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread."</p>
  
  <p>The Problem is that ISynchronize Invoke does not seem to work with wpf? Threres an compiler error message that mainWindow can´t be converted to ISynchronizeInvoke.</p>
  
  <p>if I use 
  ISynchronizeInvoke target = mainWindow as ISynchronizeInvoke;
  it can be compiled but target is null;</p>