title: Is there a way to not have a WPF MainWindow method terminating to avoid threading?
body: <p>I'm currently working on a WPF project that is trying to continuously update a listbox based on a network streamed source.</p>
  
  <p>It is my understanding that a <code>initializeComponent()</code> method will only actually display the WPF window once the <code>MainWindow()</code> method has terminated. However I am trying to have a <code>while(true)</code> loop inside it in order to continuously listen for update signals from a server and update the listbox with appropriate values.</p>
  
  <p>Each individual method is working fine, it's just that it doesn't open the WPF window in its current form due to the while loop. I am trying to avoid using a background update thread in order to update the list box because I am aware that I would have to implement functionality in order to pass the thread "ownership" of the listbox to the thread and I'm not 100% sure of how to do this.</p>
  
  <p>Is there a workaround, or better yet, is there something obvious that I'm missing to achieve my required functionality?</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>public MainWindow()
  {
      TcpClient client = new TcpClient();
      client.Connect(serverAddress, port);
      NetworkStream stream = client.GetStream();
  
      numberOfPumps = 0; //initialize as 0 on startup.
  
      handshake(stream);            
  
      InitializeComponent();
  
      updatePumpList(stream);
      updateListBox();
  
      while(true)
      {
  
          updatePumpList(stream);
          updateListBox();
      }           
  }
  </code></pre>
  
  <p>The <code>updateListBox()</code> method is simply adding items to the listbox from a dictionary.</p>
  
  <pre><code>private void updateListBox()
  {
      foreach(KeyValuePair&lt;string, PumpItem&gt; kvp in pumpDict)
      {
          pumpListBox.Items.Add(kvp.Key + ": " + kvp.Value.state);
      }
  }
  </code></pre>