【发布时间】:2012-05-24 07:27:28
【问题描述】:
我正在使用WPF Toolkit 提供的MessageBox。我得到了错误
调用线程必须是STA,因为很多UI组件都需要这个
new Thread(new ThreadStart(delegate
{
MessageBox.Show("Opeartion could not be completed. Please try again.","Error",MessageBoxButton.OK,MessageBoxImage.Error);
})).Start();
在这种情况下如何设置 ApartmentState
编辑: 我正在尝试使用 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();
}
}
【问题讨论】:
标签: c# wpf sta apartment-state