Skip to content

Document TryBeginInvoke instead of the BeginInvoke the library doesn't have [patch] - #90

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/70-readme-tryBeginInvoke
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/70-readme-tryBeginInvoke

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #70

This is the issue's option 1, the docs-only fix that the triage said to do right away. Adding IsInvokerThread and HasPendingInvokes (option 2) is a separate API decision, and this PR doesn't make it.

What changed in README.md

  • Asynchronous Invocation and Game Loop Integration: BeginInvoke(...) → TryBeginInvoke(...), with the false (queue full, action dropped) case handled.
  • Asynchronous Invocation also hung as written. It awaited the background Task.Run before calling DoInvokes(), but that task was itself awaiting an InvokeAsync that only DoInvokes() can complete. That's the same wrong-thread pattern as Invoker.Demo hangs forever: after await Task.Run(DoInvokes), Main resumes on a pool thread and its next Invoke() waits on a pump nobody calls #69. The sample now pumps DoInvokes() until the background task finishes.
  • API reference: the Properties table (IsInvokerThread, HasPendingInvokes) is gone. The BeginInvoke → void row is now TryBeginInvoke → bool, with its queue-full and owner-thread behaviour.
  • Custom Thread Identification overrode a protected virtual IsOwnerThread() that doesn't exist. The owner thread is private and fixed at construction. That section is replaced by Choosing the Owner Thread and Queue Capacity, which explains that the constructing thread is the owner and documents the beginInvokeCapacity constructor argument.

Test

Invoker.Test/ReadmeTests.cs checks the README against Invoker by reflection:

  • every invoker.X / _invoker.X in a C# sample is a public member
  • every override in a sample names an overridable member
  • every row of the Invoker API reference exists, and plain return types (void, bool, Task) match an overload
  • the Asynchronous Invocation sample's pattern completes under a 10 s timeout

I ran the new tests against the old README and three failed:

README samples use Invoker members that don't exist: BeginInvoke
README samples override Invoker members that aren't virtual: IsOwnerThread
IsInvokerThread does not exist; HasPendingInvokes does not exist; BeginInvoke does not exist

With the new README, the full suite passes (44/44).

Overlap with open PRs

#87 adds ValueTask rows right next to the BeginInvoke row this PR replaces, so whichever merges second gets a one-line conflict in the methods table. The fix is to keep both the new rows and the TryBeginInvoke row. #88 edits the BeginInvokeFailed event row, which this PR doesn't touch.


Generated by Claude Code

…t have [patch]

The README's two headline async samples called invoker.BeginInvoke, and the
API reference listed BeginInvoke plus IsInvokerThread and HasPendingInvokes
properties. None of the three exists, so copying either sample failed with
CS1061. The "Custom Thread Identification" sample overrode an
IsOwnerThread method that doesn't exist either: the owner thread is fixed
by whichever thread constructs the Invoker.

The samples and the methods table now use TryBeginInvoke and say that it
returns false, dropping the action, when the bounded queue is full. The
properties table is gone. The Asynchronous Invocation sample now pumps
DoInvokes until its background task finishes, rather than awaiting that
task first, which would hang on its own InvokeAsync. The custom-thread
section is replaced by one on choosing the owner thread and the
beginInvokeCapacity constructor argument.

ReadmeTests checks the README against Invoker by reflection: every
invoker./_invoker. member in a C# sample, every override, and every row
of the API reference with its plain return type. It also runs the
Asynchronous Invocation sample's pattern under a timeout.

Fixes #70

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5rmwEcdN9nYifxAwK
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

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.

README's async and game-loop examples don't compile: BeginInvoke, IsInvokerThread and HasPendingInvokes don't exist on Invoker

1 participant