ThinkGeo.com    |     Documentation    |     Premium Support

More task cancelled exceptions

Hello,

I have a mapping application that I’ve been working on and currently I am experiencing an issue with task cancellation exceptions when refreshing a layer, or attempting to center the map on a feature.

For example, I have the following method

private async Task ZoomToTugAsync() {
if (_mapView is null)
return;

if (_tugLayer.InternalFeatures.Contains("MyShape")) {
    await _mapView.CenterAtAsync(_layer.InternalFeatures["MyShape"]);
}
else {
    MessageBox.Show(
        messageBoxText: "There is no position available for MyShape",
        caption: "Error",
        button: MessageBoxButton.OK,
        icon: MessageBoxImage.Exclamation);
}

}

I get the following error, which in this case crashed the program

System.ArgumentException: Destination array was not long enough. Check the destination index, length, and the array’s lower bounds. (Parameter ‘destinationArray’)
at ThinkGeo.UI.Wpf.TileOverlay.3EU=(RectangleShape drawingExtent, Int32 zoom, Double matrixScale, Double currentScale, Collection1 cells, OverlayRefreshType overlayRefreshType, TileType tileType, Boolean withPosting, Boolean drawingBuffer, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.TileOverlay.3UU=(RectangleShape drawingExtent, OverlayRefreshType overlayRefreshType, Boolean renderToCanvas, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.TileOverlay.DrawAsyncCore(RectangleShape targetExtent, OverlayRefreshType overlayRefreshType, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.LayerOverlay.DrawAsyncCore(RectangleShape targetExtent, OverlayRefreshType overlayRefreshType, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.Overlay.DrawAsync(RectangleShape targetExtent, OverlayRefreshType refreshType, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.Overlay.wkU=(Exception e, String memberName) at ThinkGeo.UI.Wpf.Overlay.DrawAsync(RectangleShape targetExtent, OverlayRefreshType refreshType, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.MapViewBase.LkU=(Overlay overlay, RectangleShape targetExtent, OverlayRefreshType refreshType, Boolean renderToCanvas, CancellationToken cancellationToken) at ThinkGeo.UI.Wpf.MapViewBase.KEU=(IEnumerable1 overlays, RectangleShape targetExtent, OverlayRefreshType refreshType, Boolean renderToCanvas, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.MapViewBase.GkU=(PointShape targetCenter, Double targetScale, Double rotationAngle, MapAnimationSettings animationSettings, CancellationToken cancellationToken, Boolean fromMouseInteraction)
at ThinkGeo.UI.Wpf.MapViewBase.GkU=(RectangleShape targetExtent, Double rotationAngle, MapAnimationSettings animationSettings, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.MapViewBase.CenterAtAsync(PointShape worldPoint, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.MapViewBase.CenterAtAsync(Feature centerFeature, CancellationToken cancellationToken)
at ADISSPlayApp.Mapping.MapController.ZoomToTugAsync() in D:\ADISS\Repos\ADISS Applications\ADISSPlay\ADISSPlayApp\UI\Mapping\MapController.cs:line 645

In another case, the following code block produced a similar error.

await _mapView.Dispatcher.InvokeAsync(async () => {
await _vesselsOverlay.RefreshAsync();
});

System.AggregateException: A Task’s exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Destination array was not long enough. Check the destination index, length, and the array’s lower bounds. (Parameter ‘destinationArray’))
—> System.ArgumentException: Destination array was not long enough. Check the destination index, length, and the array’s lower bounds. (Parameter ‘destinationArray’)
at ThinkGeo.UI.Wpf.TileOverlay.3EU=(RectangleShape drawingExtent, Int32 zoom, Double matrixScale, Double currentScale, Collection`1 cells, OverlayRefreshType overlayRefreshType, TileType tileType, Boolean withPosting, Boolean drawingBuffer, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.TileOverlay.3UU=(RectangleShape drawingExtent, OverlayRefreshType overlayRefreshType, Boolean renderToCanvas, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.TileOverlay.DrawAsyncCore(RectangleShape targetExtent, OverlayRefreshType overlayRefreshType, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.LayerOverlay.DrawAsyncCore(RectangleShape targetExtent, OverlayRefreshType overlayRefreshType, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.Overlay.DrawAsync(RectangleShape targetExtent, OverlayRefreshType refreshType, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.Overlay.wkU=(Exception e, String memberName)
at ThinkGeo.UI.Wpf.Overlay.DrawAsync(RectangleShape targetExtent, OverlayRefreshType refreshType, CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.Overlay.RefreshAsyncCore(CancellationToken cancellationToken)
at ThinkGeo.UI.Wpf.Overlay.RefreshAsync(CancellationToken cancellationToken)
at ADISSPlayApp.Mapping.MapController.b__83_0() in D:\ADISS\Repos\ADISS Applications\ADISSPlay\ADISSPlayApp\UI\Mapping\MapController.cs:line 989

I am currently running version 14.4.4 for both ThinkGeo.Core and ThinkGeo.UI.Wpf

Thanks in advance.

Hi Aaron,

It is the expected behavior for overlapping asynchronous operations. This exception was bubbled up on purpose to give user a chance to know when exactly the previous operation was canceled. You can just ignore this exception, either

// catch and swallow it
catch (OperationCanceledException)  
{
    // eat the exception
}

// or do Fire-and-Forget like
 _ = Map.CenterAtAsync();

You might notice some other methods (such as RefreshAsync()) does not behave this way. We swallow cancellation exceptions internally for it because that method doesn’t change the map’s state(extent). However, since CenterAtAsync, as well as some other methods such as ZoomToAsync, actively updates the map’s extent and scales, we provide the exception so you can manage the state transition logic if needed.

I hope that makes sense. Let me know if you have any questions.

Thanks,
Ben

That makes perfect sense. Thanks for the reply.

No problem, just let us know if you have any questions!