Select to view content in your preferred language

MapTool - frozen ribbon bar during geometry processing

1331
9
Jump to solution
03-17-2024 02:28 PM
nita14
by
Frequent Contributor

Dear Community,

I have a quite busy MapTool which allows user to sketch a shape and then based on its geometry, I perform some geometry operations (using GeometryEngine), http async calls and add the results to graphics layer and to a backend feature class.

here is short snippet:

 

protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
        {

            return QueuedTask.Run(async () =>
            {
           
               //logic is here

            });

        }


Unfortunately, as this is quite lengthy process, I get my Ribbon bar frozen (attached) and the graphics layer does redraw at all. Once the processing is done, the UI becomes responsive again and the graphics are displayed in the MapView.

My question is if such behaviour is expected to see as there are some operations related to MapView (adding graphics)?

Any advice is much appreciated!

Bests,

Adam

 

 

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

Note: i used 3.3, .NET 8 (just happens to be what i hv on my box). So u will need to change the target fwk back to .NET 6 and fix references - just use the Pro SDK tool for that.

target-net6.jpgpro-fix-ref.jpg 

View solution in original post

9 Replies
CharlesMacleod
Esri Regular Contributor

the screenshot looks normal. Ribbon commands, tools, etc. are disabled, not frozen, while the queued task is running. If you mouse over the ribbon do u get tooltips? does the ribbon re-paint if u drag another window over the top of it? If yes then the UI is remaining responsive and operating normally. Frozen would imply exactly that - no response to mouse over, no repaint, etc. which is different.

Note that your TOC looks enabled which is also normal. U shld be able to change the visibility of layers, etc. while the queued task is running also.

0 Kudos
nita14
by
Frequent Contributor

Dear Charles,

Thank you for the answer. In fact most of UI is grayed out. I must have done something wrong when it comes to invoking my function in a correct thread - MCT. Although, I tried to follow all your hints and best practises you shared in this video.

I am adding the screenshot of my addin's UI (attached) and the url to my Github repo, just in case you find some time to take a look on my case. The class name is Sketch<point/polyline/polygon>.cs

Some instructions:

1) Run and build the solution.
2) Go to debug mode.
3) Open any aprx and in the map view, navigate to Poland.
4) Open GUGiK tab and click Draw a point button (screen2).
5) Click on the map.

Thank you for taking your time.

BR,

Adam

 

 

 

0 Kudos
CharlesMacleod
Esri Regular Contributor

ill see what i can do. 

CharlesMacleod
Esri Regular Contributor

i think this post will help:

https://stackoverflow.com/questions/23108045/how-to-make-observablecollection-thread-safe

I think the issue u r running into is based on how u r handling the observable collections in your view model. Two things:

1 - you must lock them (see article above)

2 - Once you assign them do NOT re-assign them because that will break the binding

(ie, once u do this: var _regions = new ObservableCollection<Regions>(); do _not_ do this....._regions = some_new_list.

I also added virtualization to your region combo box. It was choking if u hit the dropdown _before_ selecting a commune (i was getting some 50,000 odd regions in the collection for the area i was using). Without virtualization, the combobox freezes when trying to fill the dropdown if there are too many values in the Regions list.

look at this post for help on virtualization: https://stackoverflow.com/questions/8198645/wpf-combobox-performance-problems-by-binding-a-large-col...

With your permission i will add the zip to the post containing the downloaded code from your repo w/my edits

nita14
by
Frequent Contributor

Dear Charles,

Thank you for the review. Please do share the zipped code here as suggested. The plugin and the source code are to be shared publically anyway. I would love to see your changes.

Tkanks!

Adam

 

 

0 Kudos
CharlesMacleod
Esri Regular Contributor

Note: i used 3.3, .NET 8 (just happens to be what i hv on my box). So u will need to change the target fwk back to .NET 6 and fix references - just use the Pro SDK tool for that.

target-net6.jpgpro-fix-ref.jpg 

nita14
by
Frequent Contributor

Dear Charles,

It works like a charm now! Thank you for spotting my mistakes and proactively correcting them. Indeed, you solved also another issue I faced related to the comboboxes with no values after restart of ArcGIS Pro.

Thanks a lot again!

Have a nice day,

Adam

0 Kudos
Denny
by
Emerging Contributor

Hi Adam!

You can try using async

protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
  return await QueuedTask.Run(async () =>
  {
    //logic is here
  });
}

 

0 Kudos
nita14
by
Frequent Contributor

Thank you Denny. Already solved!