title: Call methods in WPF window from main thread
body: <p><strong>Use case</strong><br>
  I'm developing a small application in C# that is called by another application to retrieve data from the Internet. It runs as a process on its own, but almost all of the interaction with it, is managed by the calling application. Therefor it does not have a GUI. However I'd like to add a progress bar using WPF that is shown during certain data retrievals that could take up to a minute. It's fairly easy to make an estimate of how much work is done and how much is left and therefor I find a progress bar suitable.</p>
  
  <p><strong>Research done</strong><br>
  I have a fair understanding of threading after reading large parts of Albahari's pdf on threading (<a href="http://www.albahari.info/threading/threading.pdf" rel="nofollow">http://www.albahari.info/threading/threading.pdf</a>). I have also read through a lot of posts on SO and MSDN in this matter. Most posts suggest the use of a background worker for the time consuming data retrieval while keeping the GUI in the main thread and therefor suggest solutions using a background worker. That feels awkward in this scenario though, where the main task is data retrieval and not GUI interaction.</p>
  
  <p>I've spend a bunch of hours trying to make sense of different tutorials and forum posts while trying to conform them to my problem, but I have not succeeded and now I'm pretty much back to square one. Basically I'd like to end up with the following two classes outlined below:</p>
  
  <p><strong>ProgressBarWindow</strong></p>
  
  <pre><code>public partial class ProgressBarWindow : Window
  {
      public ProgressBarWindow()
      {
          InitializeComponent();
      }
  
      public void setValue(int value) 
      {
          // This function should be available from the main thread
      }
  }
  </code></pre>
  
  <p><strong>Querier</strong></p>
  
  <pre><code>Public class Querier
  {
  
  
  
      public List&lt;Item&gt; getItems()
      {
          // call ProgressBarWindow.setValue(0);
          ...
          // call ProgressBarWindow.setValue(100);
          // call ProgressBarWindow.Close();
      }
  }
  </code></pre>
  
  <p>It's my understanding that UI must run under single threads and therefor my <code>ProgressBarWindow</code> object could not be instantiated in a new thread while at the same time be available to the main thread (kind of).</p>
  
  <p>Dispatcher.BeginInvoke appears to be my savior here but so far I haven't been able to figure out what should go into the <code>Querier</code> class and what to go in the <code>ProgressBarWindow</code> class. How can I make the two threads interact with the same instance of ProgressBarWindow?</p>
  
  <p>Please ask if you need more details and I will try to clarify.</p>