Hi I have code that creates series of maps in a project (then add lots of data layers, calculates a common legend across 5 timer periods and creates layouts (5 frames) for each climate parameter) (added as a button with ArcPro)
When in the main class it works
When put into a function it doesn't work - not error just exits the function
- tried with 2 async methods (private async void... and private async Task ...
(added as a button with ArcPro)
CODE
This works:
=======================================
protected async override void OnClick()
{
<declarations>
foreach (string map in Mapname_Series)
{
//Create the maps
Map newMap = await QueuedTask.Run<Map>(() =>
{
Map newMap2 = MapFactory.Instance.CreateMap(map, MapType.Map, MapViewingMode.Map, Basemap.None);
QueuedTask.Run(() =>
{
ArcGIS.Core.Geometry.SpatialReference sr2193 = SpatialReferenceBuilder.CreateSpatialReference(2193);
newMap2.SetSpatialReference(sr2193);
});
=======================
This doesn't
private async void CreateMaps(string[] variables, string[] rcps, string[] periods, Boolean UseSDE, string region, string region_sd)
{
<declarations>
foreach (string map in Mapname_Series)
{
//Create the maps
Map newMap = await QueuedTask.Run<Map>(() =>
{
Map newMap2 = MapFactory.Instance.CreateMap(map, MapType.Map, MapViewingMode.Map, Basemap.None);
QueuedTask.Run(() =>
{
ArcGIS.Core.Geometry.SpatialReference sr2193 = SpatialReferenceBuilder.CreateSpatialReference(2193);
newMap2.SetSpatialReference(sr2193);
});
... < goes on to add data to each map>
}