I am using the MessageBox provided by WPF Toolkit. And I get the error
The calling thread must be STA, because many UI components require this
new Thread(new ThreadStart(delegate
{
MessageBox.Show("Opeartion could not be completed. Please try again.","Error",MessageBoxButton.OK,MessageBoxImage.Error);
})).Start();
How can I set the ApartmentState in this case
Edit: I am trying to display a modeless MessageBox using MessageBox control of WPF Toolkit. So far the code I have is as follows:
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();
}
}
EDITED
According to MSDN There exists builtin modal MessageBox in WPF but if you want to use Modeless MessageBox then you have to create custom window and then show it. Creating, showing and and returning value from custom modeless MessageBox is not very tough. You can see this link
It is not wiser to use different thread for messagebox only. Anyway you can set single apartment state by following...