Hi, I'm trying to use a progress bar to show the progress of my call to tool, but it doesn't show up no matter how I put it.
private async void Button_Click_import(object sender, RoutedEventArgs e)
{
AddlayertoDatabase(); // 添加选中图层
//var progsrc=new CancelableProgressorSource(progDlg);
var map = MapView.Active.Map;
var progDlg = new ProgressDialog("进度条", "取消", 100, true);
progDlg.Show();
// 创建一个图层组
GroupLayer groupLayer = null;
await QueuedTask.Run(() =>
{
// 创建图层组
groupLayer = LayerFactory.Instance.CreateGroupLayer(map, 0, "表面模型");
});
foreach (FeatureLayer selectedLayer in _selectedLayers)
{
var fcName = selectedLayer.Name;
var fieldName = comboBox2.Text;
var gdbPath = Project.Current.DefaultGeodatabasePath;
var outputdata = System.IO.Path.Combine(gdbPath, $"{fcName}_表面模型");
await QueuedTask.Run(async () =>
{
try
{
// 构建工具箱工具的参数
var parameters = Geoprocessing.MakeValueArray(
fcName,
fieldName,
outputdata,
"MAXIMUM",
null,
cellsize
);
// 执行工具
var progsrc=new CancelableProgressorSource(progDlg);
//var environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
GPExecuteToolFlags executeFlags = GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory | GPExecuteToolFlags.RefreshProjectItems;
var results = await Geoprocessing.ExecuteToolAsync("conversion.PointToRaster", parameters, null, progsrc.CancellationTokenSource.Token, null, executeFlags);
// 处理结果
// 获取错误信息
if (results.IsFailed)
{
await QueuedTask.Run(() =>
{
Geoprocessing.ShowMessageBox(results.Messages, "工具执行失败", GPMessageBoxStyle.Error);
});
}
else
{
//MessageBox.Show("工具执行成功!");
await QueuedTask.Run(() =>
{
var rasterLayer = LayerFactory.Instance.CreateLayer(new Uri(outputdata), groupLayer) as RasterLayer;
});
}
}
catch (Exception ex)
{
await QueuedTask.Run(() =>
{
//System.Windows.MessageBox.Show($"发生错误:{ex.Message}");
System.Diagnostics.Debug.WriteLine($"发生错误:{ex.Message}");
System.Diagnostics.Debug.WriteLine($"StackTrace: {ex.StackTrace}");
});
}
});
}
progDlg.Hide();
}
Hi,
Look at the thread. You can make a search in ArcGIS Pro SDK Questions and you will find answers for the most of your questions.
If you are running ArcGIS Pro while debugging, you will not see the progress bar. Try running ArcGIS Pro directly (without debugging) and see if it shows up for you.