I have a question about threading.
I have a WPF application, that should show the status of some queries. For this I have created a class, that runs multiple queries in multiple thread (backgroundworker). I've also created an event, so I can react while the queries are running.
private void cmdStart(object sender, RoutedEventArgs e)
{
QuerySetup qs = new QuerySetup();
//Filling qs with some data
//...
SqlProxy sql = new SqlProxy();
sql.QueryCompleted += new SqlProxy.QueryCompletedEventHandler(sql_QueryCompleted);
//Starts the backgroundworker
sql.RunSQL(qs);
}
private void sql_QueryCompleted(QueryResult qr)
{
lstStatus.Items.Clear();
lstStatus.Items.Add(qr.RuntimeTotal);
//... and some more...
}
Now I get an error message that tells me, that I can't access lstStatus because it's owned by a different thread.
But why? Shouldn't the event be in the same thread as the GUI? How can I solve my problem?