我必须加载一个窗口,并且Window_Loaded
必须加载一些变量并将其显示在 Window 上。
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>
{
try
{
//code to download some variables which will show on UI of Window Loading
}
catch (Exception ex)
{
//The calling thread cannot access this object because a different thread owns it.
}
};
worker.RunWorkerCompleted += (o, ea) =>
{
};
worker.RunWorkerAsync();
}
但我得到一个线程异常。有什么方法可以在窗口中显示变量值DoWork
吗Backgroundworker
?