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 4046086
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:31:03+00:00 2026-05-20T13:31:03+00:00

Hi When i use following code: myManualResetEvent.Dispose(); Compiler gives this error: ‘System.Threading.WaitHandle.Dispose(bool)’ is inaccessible

  • 0

Hi
When i use following code:

 myManualResetEvent.Dispose();

Compiler gives this error:

 'System.Threading.WaitHandle.Dispose(bool)' is inaccessible due to its protection level.

howevr following line works fine:

 ((IDisposable)myManualResetEvent).Dispose();

is it the correct way to dispose or at runtime it might crash in some scenerios.

Thanks.

  • 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-20T13:31:04+00:00Added an answer on May 20, 2026 at 1:31 pm

    The designers of the .NET Base Class Library decided to implement the Dispose method using explicit interface implementation:

    private void IDisposable.Dispose() { ... }
    

    The Dispose method is private and the only way to call it is to cast the object to IDisposable as you have discovered.

    The reason this is done is to customize the name of the Dispose method into something that better describes how the object is disposed. For a ManualResetEvent the customized method is the Close method.

    To dispose a ManualResetEvent you have two good options. Using IDisposable:

    using (var myManualResetEvent = new ManualResetEvent(false)) {
      ...
      // IDisposable.Dispose() will be called when exiting the block.
    }
    

    or calling Close:

    var myManualResetEvent = new ManualResetEvent(false);
    ...
    // This will dispose the object.
    myManualResetEvent.Close();
    

    You can read more in the section Customizing a Dispose Method Name in the design guideline Implementing Finalize and Dispose to Clean Up Unmanaged Resources on MSDN:

    Occasionally a domain-specific name is more appropriate than Dispose. For example, a file encapsulation might want to use the method name Close. In this case, implement Dispose privately and create a public Close method that calls Dispose.

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

Sidebar

Related Questions

Why i got this error when i use following code? $customer_key = 'my_key'; $customer_securet
I use following code: Create a retry policy, when error, retry after 1 second,
I use following code to populate a Combo Box. It displays: System.Data.DataRowView instead of
I am use following code to retrieve the session variable in routes.php if($this->db_session->userdata('request_url')!=) {
I'm trying to use following code with System.nanoTime() to measure the elapsed time of
I just use following code to add an image to my project, var paper
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have an array of objects, and i use following code to get in
I use the following code to crop an image according to a rectangular selection
I use the following code to copy a particular directory and its contents to

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.