title: this.dispatcher.invoke() does not work for multithreading?
body: <p>I am having this error again: The calling thread cannot access this object because a different thread owns it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code> public void InitiateSignalAnalysisPlot()
          {
              if (_nActiveChannel &gt; 0)    // timeDomainPlotter init
              {
                  _dataX = new List&lt;double[]&gt;();
                  _dataY = new List&lt;double[]&gt;();
  
                  _dataX3 = new List&lt;List&lt;double[]&gt;&gt;();
                  _dataY3 = new List&lt;List&lt;double[]&gt;&gt;();
  
                  double[] dataXOneCh = new double[1];
                  double[] dataYOneCh = new double[1];
  
                  dataXOneCh[0] = 0;
                  dataYOneCh[0] = 0;
  
                  CirclePointMarker pm = new CirclePointMarker { Size = 5, Fill = Brushes.Transparent };
  
                  for (int i = 0; i &lt; _nActiveChannel; i++)
                  {
                      if (_nActiveStatsOneChannel &gt; 0)
                      {
                          for (int j = 0; j &lt; _nActiveStatsOneChannel; j++)
                          {
                              _dataX.Add(dataXOneCh);    // data x-y mapping init
                              _dataY.Add(dataYOneCh);
  
                              EnumerableDataSource&lt;double&gt; xOneCh = new EnumerableDataSource&lt;double&gt;(dataXOneCh);
                              EnumerableDataSource&lt;double&gt; yOneCh = new EnumerableDataSource&lt;double&gt;(dataYOneCh);
  
                              xOneCh.SetXMapping(xVal =&gt; xVal);
                              yOneCh.SetXMapping(yVal =&gt; yVal);
  
                              CompositeDataSource dsOneCh = new CompositeDataSource(xOneCh, yOneCh);
  
                              Action InitiatePlotter = delegate()
                              {
                                  LineAndMarker&lt;MarkerPointsGraph&gt; lam = timeDomainPlotter.AddLineGraph(dsOneCh,
                                                                                         new Pen(pm.Fill, 2),
                                                                                         pm,
                                                                                         new PenDescription("C" + Convert.ToString(i) + "S" + Convert.ToString(j)));
                              };
  
                              this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, InitiatePlotter);
                          }
  
                          _dataX3.Add(_dataX);
                          _dataY3.Add(_dataY);
                      }
                  }
  
                  timeDomainPlotter.FitToView();
              }
              else
              {
                  return;
              }
          }
  </code></pre>
  
  <p>The error occurs at <code>"this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, InitiatePlotter);"</code>
  This is a piece of code behind a WPF window called by the main window thread. I am confused that I have used dispatcher.invoke() to void this multithread conflicting, why I am still getting this error? If I put this piece of code int he constructor of the window being called, it works, but I just don't want to do that way. What change can I make to I avoid this error? Thanks.</p>
  
  <p>More information that might help :
  The timeDomainPlotter is in wpf window B, which is initiated (WindowB _windowB = new WindowB(); ) in window A; The code above, InitiateSignalAnalysisPlot(), is also in window B, but InitiateSignalAnalysisPlot() gets called in window A, something like _windowB,InitiateSignalAnalysisPlot(); </p>
  
  <p>If I don't Dispatcher.Invoke() it, there will also be an exception,  which is <code>The calling thread must be STA, because many UI components require this.</code>, happening at </p>
  
  <pre><code>LineAndMarker&lt;MarkerPointsGraph&gt; lam = timeDomainPlotter.AddLineGraph(dsOneCh,
                                                                                         new Pen(pm.Fill, 2),
                                                                                         pm,
                                                                                         new PenDescription("C" + Convert.ToString(i) + "S" + Convert.ToString(j)));
  </code></pre>