Breaking change with LayersAdded event in 2.6?

406
0
09-02-2020 08:33 AM
StephenRhea
New Contributor III

We have several dock panes that use Observable Collections of layers, which we initialize when the ribbon button is clicked (i.e., on the main thread). In the Module class, we subscribe to the LayersAdded event, process the event, then fire our own event that the dock panes listen to and update their collections. In 2.5 this worked fine, but in 2.6 the LayersAdded event is now being fired from the CIM thread instead of the main thread, which has caused our dock panes to crash when updating the collections. Interestingly, the LayersRemoved event is still fired from the main thread. Is this an intentional design? I haven't found anything in the release notes or other documentation.

In case anyone else is dealing with this, I found this workaround in the Community Samples:

private void onLayersAddRem(LayerEventsArgs obj)
{
    // Instead of:
    PopulateSnapList(); // This will crash now

    //Run on UI Thread to sync layersadded event (which runs on background)
    System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => { PopulateSnapList(); }));
}‍‍‍‍‍‍‍‍
0 Kudos
0 Replies