How to use WPF Background Worker

In my application I need to perform a series of initialization steps, these take 7-8 seconds to complete during which my UI becomes unresponsive. To resolve this I perform the initialization in a separate thread: public void Initialization() { Thread initThread = new Thread(new ThreadStart(InitializationThread)); initThread.Start(); } public void InitializationThread() { outputMessage(“Initializing…”); //DO INITIALIZATION outputMessage(“Initialization … Read more

The calling thread cannot access this object because a different thread owns it

My code is as below public CountryStandards() { InitializeComponent(); try { FillPageControls(); } catch (Exception ex) { MessageBox.Show(ex.Message, “Country Standards”, MessageBoxButton.OK, MessageBoxImage.Error); } } /// <summary> /// Fills the page controls. /// </summary> private void FillPageControls() { popUpProgressBar.IsOpen = true; lblProgress.Content = “Loading. Please wait…”; progress.IsIndeterminate = true; worker = new BackgroundWorker(); worker.DoWork += new … Read more