Select to view content in your preferred language

How to hide ProgressDialog displayed during OnClick handler of a button

303
3
03-23-2025 03:43 PM
EstherSmith_Dev
Regular Contributor

Hi,

I am struggling to understand the behavior of the ProgressDialog. I have some business logic to perform when user clicks a custom button in a ribbon. Part of the logic is synchronous and part is asynchronous GP Service call that user is not interested in waiting for. It seems no matter what I do, ProgressDialog remains displayed during an asynchronous call.

 

I looked at the example at https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Framework/ProgressDialog/RunDia... 

and modified RunDialogButtonsCancel classes' OnClick method slightly as below

  internal class RunDialogButtonsCancel : Button
  {
    protected override async void OnClick()
    {   //If you run this in the DEBUGGER you will NOT see the dialog
      uint maxSteps = 10;
      using (var pd = new ArcGIS.Desktop.Framework.Threading.Tasks.ProgressDialog(
          "Doing my thing - cancelable", "Canceled", maxSteps, false))
      {
        CancelableProgressorSource cps = new CancelableProgressorSource(pd);
        // Run a user cancellable process
        pd.Show();
        await
            ProgressDialogModule.RunCancelableProgress(
                cps, maxSteps);
        cps.Progressor.Value = maxSteps + 1;
        pd.Hide();
      }
      // now wait for 10 seconds to prove ProgressDialog still remains in a display making pd.Hide() above useless
      Task.Delay(10000).Wait();
    }
  }

 

And I can see that even after Hide method, the ProgressDialog remains displayed in the UI. Is there a trick to make it go away? Is it works as designed and that ProgressDialog remains displayed until the method in which it is created (OnClick event here) remains in-scope?

Thanks,

 

 

 

Tags (1)
0 Kudos
3 Replies
EstherSmith_Dev
Regular Contributor

I have also tried this but same result, the ProgressDialog remains displayed 10 seconds after cancel is clicked.

internal class RunDialogButtonsCancel : Button
{


  private async Task RunGPService()
  {
    // Call async GP Service 
    Task.Delay(10000).Wait();
  }

  protected override async void OnClick()
  {   //If you run this in the DEBUGGER you will NOT see the dialog
    uint maxSteps = 10;
    using (var pd = new ArcGIS.Desktop.Framework.Threading.Tasks.ProgressDialog(
        "Doing my thing - cancelable", "Canceled", maxSteps, false))
    {
      CancelableProgressorSource cps = new CancelableProgressorSource(pd);
      // Run a user cancellable process
      pd.Show();
      await
          ProgressDialogModule.RunCancelableProgress(
              cps, maxSteps);
      cps.Progressor.Value = maxSteps + 1;
      pd.Hide();
    }
    // Call async GP Service and dont wait for it
    _ = RunGPService();
  }
}

 

0 Kudos
EstherSmith_Dev
Regular Contributor

Looks like I need to call a task using ArcGIS.Core.Threading.Tasks.BackgroundTask.Run. Found that below works without showing the ProgressDialog

  internal class RunDialogButtonsCancel : Button
  {


    protected override async void OnClick()
    {   //If you run this in the DEBUGGER you will NOT see the dialog
      uint maxSteps = 10;
      using (var pd = new ArcGIS.Desktop.Framework.Threading.Tasks.ProgressDialog(
          "Doing my thing - cancelable", "Canceled", maxSteps, false))
      {
        CancelableProgressorSource cps = new CancelableProgressorSource(pd);
        // Run a user cancellable process
        pd.Show();
        await
            ProgressDialogModule.RunCancelableProgress(
                cps, maxSteps);
        cps.Progressor.Value = maxSteps + 1;
        pd.Hide();
      }
      // now wait for 10 seconds to prove ProgressDialog still remains in a display making pd.Hide() above useless
      //_ = RunGPService();
      ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
         Task.Delay(10000).Wait(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
    }
  }

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Not sure what ProgressDialogModule.RunCancelableProgress in your snippet does, but if you use a ProgressorSource with a maximum number of steps the progsrc.Value has to match progsrc.Max before the ProgressorDialog goes away.  I don't think you need pd.Show() or pd.Hide() as long as you use the Value and Max properties instead.   For each completed step (with a total of progsrc.Max steps) increment progsrc.Value, when progsrc.Value is equal to progsrc.Max the progressor dialog closes.
You can find a snippet here:
CancelableProgressor Class—ArcGIS Pro

 

0 Kudos