Skip to content

Suppress finalizeation of ThreadMethodEntry class #10361

Closed

Description

@kirsan31

Background and motivation

ThreadMethodEntry class have a Finalizer but not implement an IDisposable interface. So, after every call to BeginInvoke/Invoke instance of ThreadMethodEntry will end up in Freachable queue:
Snipaste_2023-11-22_14-23-10

Finalizer here to free WH:

~ThreadMethodEntry()
{
_resetEvent?.Close();
}

We have 3 cases here (for all of them ThreadMethodEntry will end up in Freachable queue any way) :

  • We not allocate WH.
  • We allocate WH and use it internally (Invoke) - we not free it. This already violate IAsyncResult.AsyncWaitHandle using rules.
  • User allocate WH through IAsyncResult.AsyncWaitHandle (BeginInvoke). And even if he properly Close this WH, ThreadMethodEntry will end up in Freachable queue :(

Proposal

Suggestions:

  • implement IDisposable?
  • register for finalization only when WH is allocated.
  • SuppressFinalize after WH disposed.

If you don't mind in principle, you can assignee this to me. I have some ideas on this matter, and will try to implement them as soon as find time.

Risks

Must be minimal...

Will this feature affect UI controls?

No

Activity

  1. added
    api-suggestion
    untriaged
    on Nov 22, 2023
  2. added
    tenet-performance
    on Nov 23, 2023
  3. elachlan commented on Nov 23, 2023

    @elachlan
    Contributor

    @kirsan31 ThreadMethodEntry is private, so I don't think a full API review is required. Do you want to submit a PR demonstrating the fix?

  4. changed the title [-]Implement IDisposable in ThreadMethodEntry class[/-] [+]Suppress finalizeation of ThreadMethodEntry class[/+] on Nov 23, 2023
  5. kirsan31 commented on Nov 23, 2023

    @kirsan31
    ContributorAuthor

    Do you want to submit a PR demonstrating the fix?

    Yea:

    If you don't mind in principle, you can assignee this to me. I have some ideas on this matter, and will try to implement them as soon as find time.

  6. kirsan31 commented on Nov 25, 2023

    @kirsan31
    ContributorAuthor

    @elachlan
    Sadly I need to wait until 17.8 become stable enough :(

    17.7.7:

    error NETSDK1209: The current Visual Studio version does not support targeting .NET 9.0. Either target .NET 9.0 or lower, or use Visual Studio version 17.8 or higher

    P.s. error text is a bit contusing 🙄

  7. removed
    untriaged
    on Nov 28, 2023
  8. added this to the .NET 9.0 milestone on Nov 28, 2023
  9. added a commit that references this issue on Dec 11, 2023
    2699855
  10. ghost added
    🚧 work in progress
    on Dec 11, 2023
  11. added a commit that references this issue on Dec 11, 2023
    7525bed
  12. removed
    api-suggestion
    on Jan 12, 2024
  13. added a commit that references this issue on Jan 14, 2024
    0d27fb1
  14. added a commit that references this issue on Feb 3, 2024
    6e7f787
  15. added a commit that references this issue on Feb 9, 2024
    e837d07
  16. added a commit that references this issue on Mar 5, 2024
    c1e2430
  17. locked and limited conversation to collaborators on Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚧 work in progresstenet-performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions