How to add an item to a ListView from another thread without causing an exception

I am trying to add a row to listView

listView1.Items.AddRange(new ListViewItem[] { item1 }); 

from another thread to the one in which it was created, and it throws an exception.

Can someone help me figure out how to do this correctly?

+4
source share
1 answer

You can use Control.Invoke() to execute your code back in the user interface thread:

 listView1.Invoke( new MethodInvoker(delegate(){ listView1.Items.AddRange(new ListViewItem[] { item1 }; ); 
+12
source

All Articles