Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6027715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:37:59+00:00 2026-05-23T04:37:59+00:00

I have a situation where I’m creating a number of IDisposable objects that encapsulate

  • 0

I have a situation where I’m creating a number of IDisposable objects that encapsulate an EventWaitHandle instance each, so that various interested parts of my app can wait on them. This instance is not directly accessible to any code outside of its owner object. It can only be accessed indirectly through wrapper calls.

Once an object signals it’s done, it is no longer useful, so it is disposed by a central manager object and tossed from its list of references.

The question now is, what to do with the encapsulated EventWaitHandle? Naturally, it should be disposed as well, and sooner rather than later, to prevent my app from leaking OS handles.

But is it safe to do that synchronously, immediately after the event is signaled by its owner object? What can happen if there are threads still waiting to be released (i.e. blocking inside a call to WaitOne())?

What is the recommended approach here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:38:00+00:00Added an answer on May 23, 2026 at 4:38 am

    I guess it’s time to close this one with my own findings.

    I couldn’t find any direct guidelines in the docs, but decided to follow the information I extracted from Raymond Chen’s blog. In his posts (I forget the exact links) he mentions Win32 API rules dictate that event’s handle must remain valid for the duration of waiting. In unmanaged world this means at least one handle to the event must remain open.

    AFAIU, .NET’s implementation uses Win32 API under the hood, with each EventWaitHandle instance corresponding to a separate unmanaged event. When EventWaitHandle.Dispose() closes the only handle to the underlying unmanaged event, this effectively renders the event instance invalid.

    In short, the right approach seems to be to build a parallel infrastructure through which event publisher can notify potential listeners that event will be going away soon. The publisher must then wait until all the listeners have “unsubscribed” (i.e. stopped waiting) before proceeding to Dispose() the event instance.

    It’s a lot of book-keeping, but ultimately, it only seems right. Hope this helps clear things for others, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation, where running a query that filters by an indexed column in
I have a situation that is well explained in this question: Range intersection /
I have a situation where my language contains some words that aren't known at
I have a situation with my app. Suppose I have 6 users, each user
I have a situation that I cannot change: one database table (table A) accepts
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation to extend the Enumerable class in c# to add the new
I have situation where a 3rd party open source product I am using is
I have situation when I need to communicate with Java process somehow. Java handling
I have situation where in the regular expression is something like this: ^b?A+b?$ So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.