We've made an Application with a MainWindow called MV.
When main starts it launches our StartProgram method as a BackgroundWorker and the Application.Run(MW);
MainWindow MW = new MainWindow();
BackgroundWorker.DoWork += (obj, e) => StartProgram(MW);
BackgroundWorker.RunWorkerAsync();
Application.Run(MW);
In StartProgram we create instances of Patient, which we want to show in our listView1. We do this by calling this method, which is in MW:
public void SetListSource(Patient p)
{
ListViewItem item = new ListViewItem("woohoo");
item.SubItems.Add("a");
listView1.Items.Add(item);
}
StartProgram stalls when it reaches listView1.Items.Add(item);
Our guess is, that it waits for MW (MainWindow), but we can't figure out how to fix it. We have a button in MW, that does somethis similar, except it only sends "1" and "a" to the listView1.
private void Sort_Button_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem("1");
item.SubItems.Add("a");
listView1.Items.Add(item);
}
Does anybody know how to make SetListSource(...) work as Sort_Button_Click(...)?
EDIT Solved with Invoke