Skip to content

Conversation

@sylveon
Copy link
Contributor

@sylveon sylveon commented Dec 5, 2021

While migrating a bunch of C++/CX, I encountered a (rather mediocre) custom Event<> implementation. After migrating its usage to winrt::event, I noticed there was two major differences between them:

  • Event<> can be copied, and it didn't seem complex to allow copying winrt::event.
  • In C++/CX, calling the destructor (or Dispose from C#) would clear the list of event handlers right away. In C++/WinRT, while manually implementing IClosable, you cannot achieve the same: the memory associated with the event handlers (and any of their captures) is only released upon the reference count reaching 0.

So, I implemented and tested both features to achieve parity

@kennykerr kennykerr requested a review from oldnewthing December 7, 2021 21:20
@kennykerr
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kennykerr
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

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

Thanks!

@kennykerr kennykerr changed the title Make winrt::event copyable and clearable Make winrt::event clearable Dec 23, 2021
@kennykerr
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kennykerr kennykerr merged commit 51ec25c into microsoft:master Dec 23, 2021
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.

3 participants