The form does not open in the center of the parent by using a C # thread

advertisements

I have a main window form (not MDI form) and when i do some process, until this process finishes, i want to show another form (a waiting form)

If i do that regular way like that

   ProgressForm = new FrmProgress();
   ProgressForm.StartPosition = FormStartPosition.CenterParent;
   ProgressForm.ShowDialog();

it works but it stucks in ShowDialog function until I close the form. I know the logic here.

Thats why I called this code with a thread like

Thread splashThread = new Thread(new ThreadStart(
                        delegate
                        {
                            ProgressForm = new FrmProgress();
                            ProgressForm.StartPosition = FormStartPosition.CenterParent;

                            ProgressForm.ShowDialog();
                            //Application.Run(ProgressForm);
                        }
                    ));

            splashThread.SetApartmentState(ApartmentState.STA);
            splashThread.Start();
    //this part is my job

            PackageExtracter packageExtracter = new PackageExtracter();
            packageExtracter.InstallPackage(openDlg.FileName);

            ProgressForm.Invoke(new Action(ProgressForm.Close));
            MessageboxHelper.ShowInfoMessage(Messages.MsgPackageInstalledSuccessfully, Messages.MsgInstallPackageTitle);
            ProgressForm.Dispose();
            ProgressForm = null;

but this time it opens top-left corner in the first monitor (evne my main application is on the second monitor)

I want to show the "waiting form" as modal and when my job finished, then hide the form.

IS there any idea?


It works like that

            Thread splashThread = new Thread(new ThreadStart(
                delegate
                {
                    ProgressForm = new FrmProgress();
                    Application.Run(ProgressForm);
                }
            ));

            splashThread.SetApartmentState(ApartmentState.STA);
            splashThread.Start();