Hello, I am working on an ArcGIS Pro SDK project, which includes running a geoprocessing tool. This tool runs 30+ seconds. Is there a good way to show progress which the tool is running?
I have found ArcGIS.Desktop.Framework.Threading.Tasks.ProgressDialog. https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic10965.html#i-heading-example. When I use the example code in my application, I don't see the progress dialog shows up (not in debug mode).
here is the code module -
public static async Task<bool> ProcessSpatialJoin(string target_feats, string join_feats, string output_feats, string search_radius)
{
//https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic10957.html
var progDlg = new ProgressDialog("Running spatial join", "Cancel", 100, true);
progDlg.Show();
var progsrc=new CancelableProgressorSource(progDlg);
System.Windows.MessageBox.Show("Progress bar show");
var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
var parameters = await QueuedTask.Run(() =>
{
var join_operation = "JOIN_ONE_TO_ONE";
var match_option = "INTERSECT";
var field_map = "";
return Geoprocessing.MakeValueArray(target_feats, join_feats, output_feats, join_operation,
"KEEP_COMMON", field_map, match_option, search_radius);
});
GPExecuteToolFlags flags = GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.GPThread;
var toolResult = await Geoprocessing.ExecuteToolAsync("SpatialJoin_analysis", parameters, environments, null, null, flags);
// dialog hides itself once the execution is complete
progDlg.Hide();
System.Windows.MessageBox.Show("Progress bar hide");
if (toolResult.IsFailed == true)
{
Geoprocessing.ShowMessageBox(toolResult.Messages, "GP Messages", toolResult.IsFailed ?
GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
}
return !(toolResult.IsFailed);
}
Solved! Go to Solution.
thank you @Wolf , I added your code in my visual studio project. It is fired by a button click . The button is added in a dockpane. The features are copied but the Progress bar doesn't show. I am not sure if it has something to do with the ArcGIS Pro version. Mine is 3.03. Visual Studio 2022. Or has something to do with running geoprocessing tool in a dockpane.
I fixed your snippet above. I guess the main issue was that the CancelableProgressor parameter for ExecuteToolAsync is missing.
protected override async void OnClick()
{
var done = await ProcessSpatialJoin(@"Crimes", @"Portland Precincts", @"C:\Data\Interacting with Maps\Interacting with Maps.gdb\Crimes_SpatialJoin", "50 Yards");
MessageBox.Show($@"Process done: {done}");
}
public static async Task<bool> ProcessSpatialJoin(string target_feats, string join_feats, string output_feats, string search_radius)
{
//https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic10957.html
var progDlg = new ProgressDialog("Running spatial join", "Cancel");
progDlg.Show();
var progsrc=new CancelableProgressorSource(progDlg);
//System.Windows.MessageBox.Show("Progress bar show");
var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
var parameters = await QueuedTask.Run(() =>
{
var join_operation = "JOIN_ONE_TO_ONE";
var match_option = "INTERSECT";
var field_map = "";
return Geoprocessing.MakeValueArray(target_feats, join_feats, output_feats, join_operation,
"KEEP_COMMON", field_map, match_option, search_radius);
});
GPExecuteToolFlags flags = GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory;
var toolResult = await Geoprocessing.ExecuteToolAsync("SpatialJoin_analysis", parameters, environments, progsrc.CancellationTokenSource.Token, null, flags);
//// dialog hides itself once the execution is complete
//progDlg.Hide();
//System.Windows.MessageBox.Show("Progress bar hide");
if (toolResult.IsFailed == true)
{
Geoprocessing.ShowMessageBox(toolResult.Messages, "GP Messages", toolResult.IsFailed ?
GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
}
return !(toolResult.IsFailed);
}
I tried with release 3.0 as well and it worked with 3.0 too:
Thanks so much @Wolf for sticking my questions. Yes, after modifying code line 29, the progress dialog showed up. The output is created in the map. But the progress bar never hide. Then I added progDlg.Hide(); after line 29 to hide the progress dialog. Then the progress dialog disappears after the spatial join is complete.