ThinkGeo.com    |     Documentation    |     Premium Support

"A task was canceled" exceptions for point layers

Hi, I’ve been getting a lot of “A task was canceled” exceptions recently related to the tile cache.

They happen when turning the visible to invisible & back before it is finished rendering.
This is quite a big performance hit for Point based layers because the Exception is thrown for every single cancelled point. So having a layer with 50 points will throw an exception 50 times.
Is there any way we can improve this? Optimally it should throw 1 exception for the layer.

[System.Threading.Tasks.TaskCanceledException thrown]	
System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()	Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task, System.Threading.Tasks.ConfigureAwaitOptions options)	Unknown
ThinkGeo.Core.dll!ThinkGeo.Core.TileCache.9UA=.MoveNext()	Unknown
ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.TileOverlay.OEk=.MoveNext()	Unknown

Julian, can you show me a code snippet to recreate this issue?

Hi Ben, I created a repro project, please let me know what email I can send it to as it cannot be publicly shared.
Also, I narrowed down the possible issue, it is actually triggered when zooming twice before the first zoom was completed, and the tilecache canceling the tile saving. This already happens with an empty map with a filerastertilecache, it just gets more intense with a layer in.

private void MapView_Loaded(object sender, RoutedEventArgs e)
{
    MapView.MapUnit = GeographyUnit.Meter;

    var layerOverlay = new LayerOverlay
    {
        DrawingQuality = DrawingQuality.HighSpeed,
        TileType = TileType.MultiTile,
        TileCache = new FileRasterTileCache("./", "Test"),
        TileBuffer = 1
    };
    MapView.Overlays.Add(layerOverlay);
    _= MapView.RefreshAsync();
}

and enable all exceptions thrown.

Latest beta (14.5.0 beta65)

Please send to support@thinkgeo.com, I’m sure we can improve it.

Hi Ben, sorry for the long delay, I was on vacation, I sent the project to the email.
Thanks!

Hi Julian,

I didn’t see the task cancellation exception being thrown for each point. I do see it being thrown per tile, though.

We’ve made some improvements by shortening the exception chain. The exception is still thrown when a tile save is canceled, but it’s now swallowed earlier instead of bubbling up to higher levels. This change is available in the latest beta (079).

Please pull the latest build and see if there’s any improvement. Let me know if you still run into any issues.

Thanks,
Ben

Hi Ben, yes, youre correct, it seems to be an exception per tile, not per point or layer.
I don’t see any improvements with the latest beta.

Hi Julian,

The new version doesn’t reduce the number of internal exceptions being thrown, but you should no longer see entries like
ThinkGeo.UI.Wpf.dll!ThinkGeo.UI.Wpf.TileOverlay.OEk=.MoveNext() Unknown
in your call stack, as those exceptions are swallowed earlier in the pipeline.

The TaskCanceledExceptions are optimized and much more lightweight than typical exceptions, so even if multiple ones are thrown internally, they shouldn’t be a significant issue. Do you notice any measurable performance difference with caching enabled versus disabled?

Thanks,
Ben

Yes, sorry if that was unclear, the performance drops significantly when caching is enabled and the exceptions are thrown. It is much more performant without caching.

Okay, the exception being thrown rather slow on my laptop might be just an issue of the tiles loading slow and thus it just looks like the exceptions slow things down.

Thanks for letting us know!

1 Like