Hi,
I wanted to use a progress bar in a dialog.The dialog will be called when app is loading. once the app loads , the dialog should be closed.any sample code for this. ?
System.Threading.Thread mthread = new System.Threading.Thread(() => { bar = new ProgressBar(); bar.ShowInTaskbar = false; bar.SleepTime = System.Convert.ToInt32(2000); bar.ShowDialog(); } ); mthread.SetApartmentState(System.Threading.ApartmentState.STA); mthread.Start(); var X= new X() { StartupEventArgs = e };
X.Run(); bar.Dispatcher.BeginInvoke(new System.Action(() => { bar.Close(); })); bar.Dispatcher.Thread.Abort(); mthread.Abort(); App.Current.Dispatcher.Thread.SetApartmentState(System.Threading.ApartmentState.STA); Application.Current.Dispatcher.BeginInvoke(new System.Action(() => { App.Current.MainWindow.Show(); }));
Basically X is like bootstrapper.It loads the data.Now when the last line is executed , i get the foloowing error - The calling thread cannot access this object because a different thread owns it.
bar is a dialog that i am opening.I have a progress bar in that dialog.
Please help
Hello Raja,
I have been looking into your questions and I can suggest you have a look in our sample browser under the section XamDataGrid->Data Binding and Interaction->XamDataGrid Performance where is implemented similar scenario using BackgroundWorker. In this sample at the moment you request generating of the data, the application shows dialog window to announce the progress.
If you have any additional questions on this matter, please do not hesitate to ask.