Skip to content

Remove unnecessary Task.Run from androidtest template#11339

Merged
simonrozsival merged 1 commit into
mainfrom
jonathanpeppers/remove-task-run-from-template
May 14, 2026
Merged

Remove unnecessary Task.Run from androidtest template#11339
simonrozsival merged 1 commit into
mainfrom
jonathanpeppers/remove-task-run-from-template

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Description

OnStart() in the androidtest template wrapped all its async work in Task.Run(async () => { ... }). This is unnecessary because OnStart() is an instrumentation callback -- not a UI-thread method -- and the work inside is already async. The Task.Run just adds an extra thread pool hop and allocation for no benefit.

This change makes OnStart an async void method directly, which is the appropriate pattern for framework callbacks that have comprehensive try/catch error handling.

  • Useful description of why the change is necessary.
  • N/A - Links to issues fixed
  • N/A - Unit tests (template-only change, no runtime behavior difference)

OnStart() is an instrumentation callback (not UI-thread bound) and the
work is already async, so the Task.Run just adds an unnecessary thread
pool hop and allocation. Making OnStart async void is appropriate here
since it is a framework callback with comprehensive try/catch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 21:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR simplifies the androidtest template instrumentation startup path by removing an unnecessary Task.Run wrapper around already-async test execution work.

Changes:

  • Changes OnStart() to async void, matching the framework callback pattern.
  • Moves the existing async test setup/run/reporting logic directly into OnStart().
  • Preserves existing try/catch handling and result bundle reporting.

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label May 14, 2026
jonathanpeppers added a commit that referenced this pull request May 14, 2026
Run tests directly on the instrumentation thread instead of a .NET
thread pool thread. Java.Lang.JavaSystem.LoadLibrary and Runtime.Load
both use the calling thread's ClassLoader to resolve native library
paths. On a thread pool thread there are no Java frames on the stack,
so the ClassLoader is null and app-private .so files cannot be found.

This matches the approach in PR #11339 for the androidtest template.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival merged commit 6996a6d into main May 14, 2026
7 checks passed
@simonrozsival simonrozsival deleted the jonathanpeppers/remove-task-run-from-template branch May 14, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants