Tuesday, November 16, 2010

How can I access my Mainwindow-controls from a thread?

public MainWindow()
{
      InitializeComponent();

      Thread workerThread = new Thread(WorkerThread);
      workerThread.Start();
}

private void WorkerThread()
{
      UpdateWindowText(this);
}

private void UpdateWindowText(Window window)
{
      window.Dispatcher.Invoke((Action) (() => window.Title = "test"));
}

No comments:

Post a Comment