Hi Team,
With GpuBasemap enabled (ThinkGeo.UI.Wpf / ThinkGeo.Gpu 15.0.0-beta197), our log fills with unobserved task exceptions. They appear after we add a layer or toggle WMS/WFS layers. Dozens arrive in bursts whenever the finalizer runs:
System.AggregateException: A Task's exception(s) were not observed ...
---> System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.<VerifyAccess>g__ThrowVerifyAccess|7_0()
at ThinkGeo.UI.Wpf.MapViewBase.A(IEnumerable`1, CancellationToken)
at ThinkGeo.UI.Wpf.MapViewBase.RefreshAsync(OverlayRefreshType refreshType, CancellationToken cancellationToken)
Our own RefreshAsync calls are all awaited on the UI thread. When we inspected the beta197 assemblies, we found the following:
- The GPU overlay that
GpuBasemapattaches implementsIGpuMapHost.RequestMapRefresh()asMapView.RefreshAsync(). The task is not awaited, and the call is not marshalled to the map’s dispatcher. -
GpuMapControllercallsRequestMapRefreshfrom:-
RefreshVectorTiles, which also runs from theFeatureSourceVectorTileSource.DataChangedhandler, so on whichever thread raised that event; -
RefreshRasterTiles; - style application;
- the coverage watchdog.
-
-
RefreshAsynchas no thread check of its own. An off-thread call therefore proceeds untilMapViewBasereads an overlay’sParentwhile opening overlays. It then throws, the refresh is lost, and the exception only surfaces later throughTaskScheduler.UnobservedTaskException.
Other host callbacks already go through TryPostToUi , and GpuBasemap marshals its automatic restyle to the dispatcher. Could RequestMapRefresh do the same, for example Dispatcher.InvokeAsync(() => map.RefreshAsync()) , and observe or log the resulting task?
We can’t work around this on our side. RefreshAsync is not virtual, and the exception happens before DrawAsyncCore runs, so a MapView subclass never sees the call.
We haven’t yet pinned down which controller path runs off the UI thread in our application.
Thanks!