Reputation: 6725
I try to add a row to a listView
listView1.Items.AddRange(new ListViewItem[] { item1 });
from a different thread to the one in which it was created and it throws an Exception.
Can anyone help me understand how to do this correctly?
Upvotes: 4
Views: 3100
Reputation: 245479
You can use Control.Invoke()
to execute your code back on the UI thread:
listView1.Invoke(
new MethodInvoker(delegate(){
listView1.Items.AddRange(new ListViewItem[] { item1 };
);
Upvotes: 13