954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

WPF New thread opens new window, how to update text box in new window?

Hello

I have the following code for a WPF application here is the code


Code from MainWindow.xaml.cs

public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
      Thread[] threads = new Thread[3];

      for (int i = 0; i < 3; i++)
      {
        int index = i;
        threads[i] = new Thread(new ThreadStart(test));
        threads[i].SetApartmentState(ApartmentState.STA);
        threads[i].IsBackground = true;
        threads[i].Start();
      }
    }

    public void test()
    {
      OutputWindow outputwindow = new OutputWindow();
      outputwindow.Show();
      System.Windows.Threading.Dispatcher.Run();

      outputwindow.textBox1.Text = "writing";
      //some more stuff done
      //some more stuff done
      //some more stuff done
      outputwindow.textBox1.Text = "\nmore writing";
      //some more stuff done
      //some more stuff done
      //some more stuff done
      outputwindow.textBox1.Text = "\nmore writing";
    }
  }


How can I make textBox1.Text actually get updated as test() is being executed?


Regards!

arya6000
Newbie Poster
14 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: