멀티 스레드를 사용하여 ItemsControl에 항목 (UserControl)을 설정하려고합니다. 내 코드는이멀티 스레드를 사용하여 ItemsControl에 Usercontrol을 추가하는 방법?
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(SetItemsControl));
thread.Start();
void SetItemsControl()
{
IDictionary<string, object> list = GetUserControlList(); // this function return list of UserControl
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new Action(delegate()
{
mylistcontrol.ItemsSource = list;
}));
}
좋아하는 많은 UI 구성 요소이 필요하기 때문에 그것은 내 UserControl을
호출 스레드가 STA를해야 내 초기화 기능에서 나옵니다.
어떻게 해결할 수 있습니까 ??
thread.SetApartmentState (ApartmentState.STA);를 설정할 수 있습니다. 시작하기 전에. 다른 문제가 발생할 지 모르겠다. – Dtex
예. 나는 노력했다. 스레딩 문제가 발생했습니다. 다른 스레드가 스레드를 소유하고 있기 때문에 호출 스레드가이 개체에 액세스 할 수 없습니다. – ChauGiang