1
WPF Toolkit에서 제공하는 MessageBox를 사용하고 있습니다. 내가 노력하고 있어요 : 그리고 나는 많은 UI 구성 요소 I 편집많은 UI 구성 요소에이 WPF가 필요하기 때문에 호출 스레드는 STA 여야합니다.
을이 경우에 ApartmentState을 설정하는 방법이
new Thread(new ThreadStart(delegate
{
MessageBox.Show("Opeartion could not be completed. Please try again.","Error",MessageBoxButton.OK,MessageBoxImage.Error);
})).Start();
을 필요로하기 때문에
가 호출 스레드는 STA를해야 오류를 얻을 WPF Toolkit의 MessageBox 컨트롤을 사용하여 모덜리스 MessageBox를 표시합니다.
void SomeFunction()
{
// calls to some UI, and processing and then
var th = new Thread(new ThreadStart(delegate
{
MessageBox.Show("Opeartion could not be completed. Please try again.",
"Error", MessageBoxButton.OK, MessageBoxImage.Error);
}));
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
}
왜 당신이 대화 상자를 표시하는 단지 새 스레드를 시작합니까 :
다음은 호출자가 다른 스레드에있을 때 TextBox.Text 속성을 수정하는 방법의 예입니다? 기존 UI 스레드에 신호를 보내서 표시하는 것이 훨씬 낫습니다. 자동으로 문제를 해결할 수도 있습니다. – Jon
http://stackoverflow.com/questions/4183622/the-calling-thread-must-be-sta-because-many-u-components-require-this-in-wpf – Klaus78
@ 존 완전히 동의합니다. 절대적으로 있습니다. 새 스레드를 스핀하여 메시지 상자를 표시 할 이유가 없습니다. 이 스레드를 잠글 수있는 대화 상자 일지라도 새 스레드를 제안하지는 않습니다. Dispatcher를 사용하는 것이 좋습니다. – erodewald