Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1085
Progress bar
posted

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. ?

Parents
  • 1085
    posted

    Hi,

    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

Reply Children