Repository navigation
[Events] Run every raise of an external event and cancel a pending raise - #133
Merged
Merged
Conversation
This was
linked to
issues
Oct 23, 2026
Nice3point
marked this pull request as ready for review
October 24, 2026 10:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
What is this about:
Every raise of an external event runs its handler with its own argument, and a caller can withdraw a pending
RaiseAsyncwith a token.Description:
What changed
ExternalEvent<T>queues the argument of everyRaise(argument)and runs the handler once per argument, in the order of the raises.RaiseAsynccall with its own task.Executeruns one queued raise per Revit event cycle and raises the event again while raises remain.ExternalEventwithout an argument is unchanged: Revit runs it once for all raises that wait.Raise()inherited fromExternalEventHandlerqueues a separate execution on the asynchronous events and onExternalEvent<T>. Events with an argument use the last supplied argument, as in 2027.0.2. The guides leave this call out; the XML documentation of the overrides describes it.DeniedorTimedOutnever runs.Raise(argument)returns that result, and theRaiseAsynctask fails with anInvalidOperationException.RaiseAsync(CancellationToken)next toRaiseAsync(), which passesCancellationToken.None.(UIApplication, [T,] CancellationToken).CancellationTokenparameter of the handler and generates the async extension method for several arguments as a pair of overloads.Nice3point.Revit.Toolkit.Tests.RVTTK0006andRVTTK0007move to the 2027.0.1 release ofAnalyzerReleases.Shipped.md, and the compiler tooling fixes move to the 2027.0.1 section of the changelog. Tag 2027.0.0 contains neither.The token affects a raise as follows:
OperationCanceledExceptionfor itWith
AllowDirectInvocationin API mode the token is checked once, before the handler runs.Generated code for
void Run(UIApplication application, int quantity, string label, CancellationToken cancellationToken):The synchronous
RunEventpassesCancellationToken.Noneto the handler.Where to look
AsyncExternalEventCore<TArgument, TResult>andExternalEventCore<TArgument>. They receive the RevitRaiseas a delegate, and the event classes keep only the direct invocation and the last argument forRaise().System.Threading.Channels:VoidResultstands for the absent argument or result;ConcurrentQueueis checked withIsEmpty;TryReserveCompletion,DangerousSetResult);Raise()has no task. Its handler exception leavesExecutethrough the filterwhen (operation.Task is not null), and Revit catches it.Raise(), and the cores receivebase.Raise. The compiler emitsldftn ExternalEventHandler::Raise()for all 14 delegates. The cores call the Revit raise without virtual dispatch, and an override never calls itself.ExecutereturnsAcceptedand triggers the nextExecute, at about 1.3 ms per cycle. Draining the whole queue in oneExecutewas the alternative; it holds the Revit UI for the batch and loops forever when a handler raises its own event.Executeraises the event again before it runs the handler. A handler exception doesn't stall the queue.OperationCanceledExceptioncancels the task only for the token of the raise, the same rule asTask.Run. Any otherOperationCanceledExceptionfaults the task.(UIApplication, [T,] CancellationToken). AnAction<CancellationToken>constructor would make an existing untyped lambdax => …ambiguous withAction<UIApplication>.Accepted, and 2400 concurrent raises returned noTimedOut. The refusal paths are covered with a fakeRaisein the core tests, throughInternalsVisibleTo.How verified
Release.R20toRelease.R27, the generator, and its.Roslyn414twin, with zero errors and zero compiler warnings.Quality Checklist