Why do Progress Dialogs cause errors (when setting message, or showing), after being hidden once?

742
0
03-02-2018 11:58 AM
Justin_ODell
New Contributor III

Questions:

  1. After IProgressDialog2 method HideDialog() is called, can the same progress dialog be shown again by calling ShowDialog()?
  2. Does IProgressDialog2 method HideDialog() hide the progress dialog or does it actually close the dialog; thus meaning once hidden that dialog can not be used again?
  3. Why does IStepProgressor.Message setter throws a System.Runtime.InteropServices.SEHException if called after HideDialog()?

Errors occur when using the progressDialog after it has been hidden once:

  • stepProgressor.Message() and IProgressDialog2.ShowDialog() do not work after calling IProgressDialog2.HideDialog(), as shown in the code sample below
  • ShowDialog seems to have no effect after the progress dialog has been hidden
  • Setting stepProgressor.Message after calling progressDialog.HideDialog() causes the following error
    System.Runtime.InteropServices.SEHException: External component has thrown an exception.
      at ESRI.ArcGIS.esriSystem.IStepProgressor.set_Message(String Message)
      at TestExtension2.MyButton2.OnClick() in C:\temp\clsExt2.cs:line 148

Environment:

ArcMap 10.2, 10.2.2 Basic, 10.4 standard, 10.6 Basic
Windows 7 Enterprise(64 - bit) 6.1.7601 Service Pack 1
Visual Studio 2015 C#   (We had similar results when running VB 6 code with the same objects except that the error was "Encountered an improper argument.")

Sample code:

The following code should, display a progress dialog that updates a message to show the loop counter.

At 10,000, the progress dialog hides. After hiding, the next iteration causes an error on the message line (15).

If you comment out the message line, it should count up to 10,000, hide the progress dialog, and show it again at 20,000 -- however the progress dialog does not show again.

        public override void OnClick()
        {
            try
            {
                IProgressDialogFactory progressDlgFact = new ProgressDialogFactoryClass();
                IProgressDialog2 progressDialog = (IProgressDialog2)progressDlgFact.Create(null, 0);
                IStepProgressor stepProgressor = (IStepProgressor)progressDialog;

                progressDialog.Title = "Please Wait...";

                progressDialog.ShowDialog();
                for (int i = 1; i < 50000; i++)
                {
                    //stepProgressor.Position = i;                 // when this line is called after hide dialog (instead of .message = ), no error occurs
                    stepProgressor.Message = "Processing " + i;    // when this line is called after hide dialog, SEHException occurs
                    if (i == 10000)
                    {
                        progressDialog.HideDialog();
                    }
                    if (i == 20000)
                    {
                        MessageBox.Show("20K");
                        progressDialog.ShowDialog();                // if the stepProgressor.Message line is commented out, this line does not make the dialog reappear
                    }
                }
                MessageBox.Show("Done");
                progressDialog.HideDialog();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
0 Kudos
0 Replies