How do I add an item to a ListView from another thread without causing an exception
I try to add a row to a listView
listView1.Items.AddRange(new ListViewItem[] { item1 });
from a different thread to the one in whic开发者_如何学编程h it was created and it throws an Exception.
Can anyone help me understand how to do this correctly?
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 };
);
精彩评论