Tech Off Post

Single Post Permalink

View Thread: Open new WPF Window / Multithreading
  • User profile image

    jh71283 wrote:
    Object reference not set to an instance of an object.

    is nothing

    Bearing in mind that the application is winforms based, what is the winforms equivalent to System.Windows.Application.Current.Dispatcher?

    Below is a code example on how to do this.  Basically you need to create the Window in a delegate that is passed to the Invoke method on any control in your Windows Forms solution.

    using System;
    using System.Windows.Forms;
    using System.Threading;

    namespace WPFHost
        public partial class Form1 : Form
            public Form1()

            private void button1_Click(object sender, EventArgs e)
                Thread thrd = new Thread(new ThreadStart(
                    delegate() {
                        this.Invoke(new MethodInvoker(CreateWindow));

            public void CreateWindow()
                System.Windows.Window wnd = new System.Windows.Window();