Select to view content in your preferred language

Progress bar status trouble

432
2
05-08-2023 06:29 PM
DeviceWorksOfficial
New Contributor

Hello, I've been using ArcGIS Pro 2.9.4, and using ArcGIS SDK to implement progress bar to show how long it will take until the process ends.

I want nothing under the progress bar, but status "finishing up..." always show up.

How could I get rid of it?

0 Kudos
2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Assuming that you are using the CancelableProgressorSource:

You can try setting the following properties for the CancelableProgressorSource instance to change the Progress bar UI:

//     Gets or sets the message of the progress dialog displayed while the associated
//     Task is executing.
public string Message { get; set; }

//     Gets or sets the status of the progress dialog displayed while the associated
//     Task is executing.
public string Status { get; set; }

//     Gets or sets the extended status of the progress dialog displayed while the associated
//     Task is executing.
public string ExtendedStatus  { get; set; }

//     Gets or sets the progress bar position within the progress dialog displayed while
//     the associated Task is executing.
public uint Value  { get; set; }

//     Gets or sets the progress bar maximum value within the dialog displayed while
//     the associated Task is executing.
public uint Max { get; set; }

Unfortunately, this class is not listed in our API Reference, I am trying to get this fixed with the next release.  

Below is a sample tool that i using the progress bar and changes its properties:

/// <summary>
/// This tool can be used to digitize a polygon on a map and once complete
/// the tool performs a series of buffer operations with expanding buffers
/// During the buffer creation process the Progress Dialog is displayed
/// </remarks>
internal class MultiBufferTool : MapTool
{
  /// <summary>
  /// Constructor of BufferGeometry tool
  /// </summary>
  public MultiBufferTool()
  {
    IsSketchTool = true;
    SketchType = SketchGeometryType.Polygon;
    SketchOutputMode = SketchOutputMode.Map;
  }

  /// <summary>
  /// Constructs the value array to be passed as parameter to ExecuteToolAsync
  /// Runs the Buffer tool of Analysis toolbox
  /// </summary>
  /// <param name="geometry"></param>
  /// <returns>Geoprocessing result object as a Task</returns>
  protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
  {
    uint numBuffers = 7;

    // create and initialize the progress dialog
    // Note: Progress dialogs are not displayed when debugging in Visual Studio
    var progDlg = new ProgressDialog($@"Creating {numBuffers} buffers", "Canceled", false);
    var progsrc=new CancelableProgressorSource(progDlg);
    for (uint iBuffer = 1; iBuffer <= numBuffers; iBuffer++)
    {
      var valueArray = await QueuedTask.Run<IReadOnlyList<string>>(() =>
      {
        var geometries = new List<object>() { geometry };
        // Creates a 100-meter buffer around the geometry object
        // null indicates a default output name is used
        var valueArray = Geoprocessing.MakeValueArray(geometries, null, $@"{iBuffer*100} Meters");
        return valueArray;
      });
      progsrc.ExtendedStatus = $@"Creating buffer #: {iBuffer} of {numBuffers}";
      progsrc.Value = 100 * (iBuffer-1);
      progsrc.Max = 100 * numBuffers + 1;
        
      var gpResult = await Geoprocessing.ExecuteToolAsync("analysis.Buffer", valueArray, null, progsrc.Progressor);
      if(gpResult.IsFailed)
      {
        // display error messages if the tool fails, otherwise shows the default messages
        if (gpResult.Messages.Count() != 0)
        {
          Geoprocessing.ShowMessageBox(gpResult.Messages, progsrc.Message,
                          gpResult.IsFailed ?
                          GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
        }
        else
        {
          MessageBox.Show($@"{progsrc.Message} failed with errorcode, check parameters.");
        }
        break;
      }

      // check if the operator cancelled
      if (progsrc.CancellationTokenSource.IsCancellationRequested) break;
    }
    if (progsrc.CancellationTokenSource.IsCancellationRequested)
    {
      MessageBox.Show("The operation was cancelled.");
    }
    return true;
  }
}

The above sample code displays the progressbar like this:

Wolf_0-1683636758748.png

 

0 Kudos
RichardDaniels
Regular Contributor
Sounds like you are using some internal project bar related to the tool you are running, vs. one you wrote yourself. When you need full control of the bar use a System.Windows.Forms.ProgressBar on a WinForm . For example, here I'm loading a database into memory within an ArcGIS Pro addin.
[cid:image001.png@01D98250.8426CC30]
Code behind looks similar to this.
private Form myProgressBar;
public void LoadDatabase (SqlDataReader theDataSource)
{
if (myProgressBar==null)
{
myProgressBar = new wsdotCode.frmProgress();
}
System.Windows.Forms.ProgressBar pbar;
pbar = myProgressBar.Controls.Find("progressBar1", true).FirstOrDefault() as System.Windows.Forms.ProgressBar;
pbar.Value = 0;
myProgressBar.Show();
//increment the progress bar and read data

While not EOF(theDataSource)

{

LoadRow(theDataSource)

progressUpdate(pbar);

}

myProgressBar.Close();

}


private void progressUpdate(System.Windows.Forms.ProgressBar myBar)
{
//step size is set in the designer
myBar.PerformStep();
myBar.Refresh();
myBar.Parent.Refresh();
if (myBar.Value >= 100)
{
System.Threading.Thread.Sleep(200);
}
else
{
System.Threading.Thread.Sleep(100);
}

}
0 Kudos