I have a problem with ListViewItem.When i use it in a thread, it display a message:
"The calling thread must be STA, because many UI components require this."
and then I change it to :
Mythread.SetApartmentState(ApartmentState.STA);
Although when I use it, it display a message again:
"The calling thread cannot access this object because a different thread owns it."
I use Dispatcher for it. It display a message again:
"The calling thread cannot access this object because a different thread owns it."
what am I doing to solve problem?
Thread th = new Thread(() =>
{
search.SearchContentGroup3(t, addressSearch.CurrentGroup.idGroup);
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
public void SearchContentGroup3(int id)
{
ListViewItem lst = new ListViewItem();
lst.DataContext = p;
Application.Current.Dispatcher.BeginInvoke(
new Action(() => currentListView.Items.Add(lst)),
DispatcherPriority.Background);
}