Questions:
- After IProgressDialog2 method HideDialog() is called, can the same progress dialog be shown again by calling ShowDialog()?
- 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?
- 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.
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">override</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">OnClick</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
IProgressDialogFactory progressDlgFact <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ProgressDialogFactoryClass</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
IProgressDialog2 progressDialog <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IProgressDialog2<SPAN class="punctuation token">)</SPAN>progressDlgFact<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Create</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
IStepProgressor stepProgressor <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>IStepProgressor<SPAN class="punctuation token">)</SPAN>progressDialog<SPAN class="punctuation token">;</SPAN>
progressDialog<SPAN class="punctuation token">.</SPAN>Title <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Please Wait..."</SPAN><SPAN class="punctuation token">;</SPAN>
progressDialog<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ShowDialog</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">for</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN> i <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN> i <SPAN class="operator token"><</SPAN> <SPAN class="number token">50000</SPAN><SPAN class="punctuation token">;</SPAN> i<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//stepProgressor.Position = i; // when this line is called after hide dialog (instead of .message = ), no error occurs</SPAN>
stepProgressor<SPAN class="punctuation token">.</SPAN>Message <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Processing "</SPAN> <SPAN class="operator token">+</SPAN> i<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// when this line is called after hide dialog, SEHException occurs</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>i <SPAN class="operator token">==</SPAN> <SPAN class="number token">10000</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
progressDialog<SPAN class="punctuation token">.</SPAN><SPAN class="token function">HideDialog</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>i <SPAN class="operator token">==</SPAN> <SPAN class="number token">20000</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"20K"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
progressDialog<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ShowDialog</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// if the stepProgressor.Message line is commented out, this line does not make the dialog reappear</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Done"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
progressDialog<SPAN class="punctuation token">.</SPAN><SPAN class="token function">HideDialog</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>