I want to add a progress bar in the Active Map that "spins" left-to-right
while a CreateLayer geoprocessing tool is loading the polygons.
There are 2K+ polygons and so it takes a bit of time to load. Once all are loaded,
I want the progress bar to disappear.
How do I do that with the following code:
private async void BtnRun_Click(object sender, RoutedEventArgs e)
{
sdePath = TboxPath.Text; //E:\WorkingFolder\SWATAddIn\MG_Connection.sde
in_features = TboxInFeature.Text; //MG.dbo.APEX_SWAT_COMP_HUC8
int lyrIndex = 0;
string lyrName = TboxLyrName.Text;
//Create and add a layer to the active map
string url = System.IO.Path.Combine(sdePath, in_features);
Uri uri = new Uri(url);
//Creat a Progress Bar user control
ProgressBar pBar = new ProgressBar();
//Create a MapViewOverlayControl.
var mapViewOverlayControl = new MapViewOverlayControl(pBar, true, true, true, OverlayControlRelativePosition.BottomCenter, .5, .8);
//Configure the progress bar
pBar.Minimum = 0;
pBar.Maximum = 100;
pBar.IsIndeterminate = true;
pBar.Width = 300;
pBar.Value = 10;
pBar.Height = 25;
pBar.Visibility = Visibility.Visible;
//Add to the active map
MapView.Active.AddOverlayControl(mapViewOverlayControl);
//Close this window
Close();
await QueuedTask.Run(() =>
{
Layer lyr = LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map, lyrIndex, lyrName);
});
}
Right now, the progress bar just keeps spinning because I don't know where to call the pBar.Hide() in the above code, without it disappearing BEFORE all polygons are loaded.
Appreciate any help.
The best way is to use the progressor argument of QueuedTask.Run https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/index.html#topic10996.html and the "built-in" Progressor class.
Looking at the "Run" method definition can be a little intimidating because of the syntax associated with the delegate parameter (eg Func<T>, Func<Task<T>>, Action, etc) but if u notice, the second parameter is of type Progressor or CancelableProgressor.
There are a couple of snippets here: non-cancelable: https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Framework#progressor---simple-and-non-cancel... and cancelable (which is a little more work): https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Framework#progressor---cancelable
In your case, based on the "simple-and-non-cancelable" snippet referenced above, you would want something like this (please note the comment regarding the Debugger - in other words when you are debugging your addin in Visual Studio you will **not** see the progressor )
private async void BtnRun_Click(object sender, RoutedEventArgs e) {
sdePath = TboxPath.Text;
//....etc
//make a progressor
var ps = new ArcGIS.Desktop.Framework.Threading.Tasks.ProgressorSource(
"Doing my thing...", false);
//Run layer create and show a progressor
//NOTE: when you run this in the DEBUGGER you will NOT see the dialog
await QueuedTask.Run(() => {
Layer lyr = LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map,
lyrIndex, lyrName);
}, ps.Progressor);
}