Skip to content

Fix UIKitThreadAccessException during chart animation on iOS#373

Open
follesoe wants to merge 1 commit into
microcharts-dotnet:mainfrom
follesoe:fix/ui-thread-invalidation
Open

Fix UIKitThreadAccessException during chart animation on iOS#373
follesoe wants to merge 1 commit into
microcharts-dotnet:mainfrom
follesoe:fix/ui-thread-invalidation

Conversation

@follesoe
Copy link
Copy Markdown
Contributor

@follesoe follesoe commented Apr 17, 2026

Summary

  • Marshal InvalidateSurface() through Dispatcher.Dispatch() in the MAUI ChartView invalidation callback to avoid calling UIKit from a background thread

The DelayTimer used by Chart.AnimateAsync fires its step callback on a background thread. This updates AnimationProgress, which triggers InvalidateSurface() -> UIView.SetNeedsDisplay(). On iOS, UIKit throws a UIKitThreadAccessException because SetNeedsDisplay must be called from the main thread.

Fixes follesoe#1

🤖 Generated with Claude Code

The DelayTimer fires its animation step callback on a background thread,
which updates AnimationProgress and triggers InvalidateSurface(). On iOS
this calls UIView.SetNeedsDisplay() which must run on the UI thread.

Marshal the InvalidateSurface() call through Dispatcher.Dispatch() in
the invalidation observer callback.

Fixes #1

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnimateAsync timer callback calls InvalidateSurface off the UI thread, crashes on iOS

1 participant