0

I want to load a form ufdiagram1 in the mainform as a dockpanel using another thread than the forms-thread of mainform. With the following code I am getting a NullReferenceException:

private UfDiagram ufdiagram1 = new UfDiagram();

privat void form1_load(...)
{
    System.Threading.Thread tThread1 = new System.Threading.Thread(new System.Threading.ThreadStart(StartDiaThread));

    tThread1.Name = "ufDiagram1";
    tThread1.Start();
}

private void StartDiaThread()
{
    ufdiagram1.Show(dockPanel1, DockState.DockRight);
    //ufdiagram1.showDialog(); //Does work in a new form but not as a dockpanel
}

Is it possible to start the ufdiagram1 docked in the mainform with another thread? If so, how does that work?

Anthony
  • 9,451
  • 9
  • 45
  • 72
Yipman
  • 1
  • Sounds like duplicate of [this](http://stackoverflow.com/q/6463894/1997232) (or similar) question. But that *another thread* part is something new. Why another thread? – Sinatr Jun 29 '15 at 13:20
  • Thanks for the link, i gonna look through it now (sounds like it is a similiar problem; Ismdicontainer = true). I want to load data in a diagram without freezing the mainform AND using the dockpanel-style for the diagram. – Yipman Jun 29 '15 at 13:30
  • Then load the data for the form in a background thread, but don't assign it to the form until it is fully loaded. You really shouldn't try creating controls across different threads. – Anthony Jun 29 '15 at 13:40
  • While Win32 allows multiple threads to create windows (controls) and pump messages, it is non-trivial to do (have to ensure the right thread is doing the right bits of the UI). But it is not clear this is a supported scenario in WinForms as there is no direct access to the message pump. However you could try creating a second (and non-background) thread, and then calling `Application.Run(new TheControl())` on it. – Richard Jun 29 '15 at 13:52

0 Answers0