-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Second event handler not called due to cswinrt delegate combining #626
Comments
Need to confirm whether WinRT supports assigning completion handlers after the first one has fired. Many languages with await support can implicitly only assign a single completion handler. |
WinRT appears to not support the above usage pattern of assigning the Completed handler multiple times: The cswinrt behavior of combining delegates is not a problem for event implementations that follow this guidance. |
Without this fix, it wouldn’t be safe for customers to reuse a CompositionScopedBatch, in that they will not get called back if they add a second handler after the first handler fires. Might not be a common scenario, but we should have a fix before Reunion 1.0 ships. |
discussing with Mano, solution would be in EventSource.Subscribe, to validate the COM ref count on the CCW for _eventInvoke and if 0, clear and recreate the cached _state |
In Microsoft.UI.Composition, the CompositionScopedBatch.Completed event is designed to fire a given event handler only once. Once this event is fired, the implementation of CompositionScopedBatch removes the event handler from the implementation's list and will no longer fire it.
In previous versions of .NET, if a 2nd event as added to the list after the first event fired, the second event would still be fireable. Using .NET5/cswinrt, the 2nd event does not end up being fired.
I think that reason is that cswinrt appears to manage the list of event handlers itself. The implementation only sees one event handler being passed to it, despite the caller actually having added 2 of them. When the first event is fired, the implementation ends up removing the entire list of event handlers rather than just the first one. So when the second event handler is added, it never gets called.
A workaround as a caller is to remove the first event handler after it is fired, and before adding the second handler. Doing this ensures that the second event handler is fired.
In this version of the calling code, the second handler is not called:
CompositionScopedBatch _batch;
In this version of the calling code, the second handler is called:
The text was updated successfully, but these errors were encountered: