I've implemented the solution from Stack Overflow question Implement progressbar in this simple WPF application.
MainWindow has its own viewmodel. Inside that viewmodel I receive the user's input and consume the WCF service using a background worker. After WCF serves the data back, I'm trying to display it in a new window. This is where the error occurs:
The calling thread must be STA, because many UI components require this.
I tried to put the [STAThread]
attribute on the MainWindow code-behind as well as inside the MainWindowViewModel contructor. In both cases nothing changed.
What am I missing?
Update After user clicks command in viewmodel call LoadData method
private void LoadData(string searchBy)
{
IsBusy = true;
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>
{
switch (searchBy)
{
// WCF call to load data
}
}
worker.RunWorkerCompleted += (o, ea) =>
{
IsBusy = false;
};
worker.RunWorkerAsync();
BackgroundWorker
? – Douglas