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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:14:23+00:00 2026-06-07T05:14:23+00:00

We can use Wait and Pulse to simulate a ManualResetEvent as follows: code #1

  • 0

We can use Wait and Pulse to simulate a ManualResetEvent as follows:

code #1

readonly object _locker = new object();
bool _signal;
void WaitOne()
{
  lock (_locker)
   {
     while (!_signal) Monitor.Wait (_locker);
   }
}

void Set()
{ 
   lock (_locker) 
      { _signal = true; 
        Monitor.PulseAll (_locker); 
      }
}

void Reset() 
   {
    lock (_locker) _signal = false; 
   }

fine

now lets talk about enhancing it to be AutoREsetEvent :

an AutoResetEvent is simply a matter of replacing the code in WaitOne with this:

code #2

lock (_locker)
{
    while (!_signal) Monitor.Wait (_locker);
    _signal = false;//<---------------
}

and replacing PulseAll with Pulse in the Set method:

code #3

lock (_locker) 
   { _signal = true; 
     Monitor.Pulse (_locker); 
   }

and here is the question :
at code #2 , the line _signal = false;.

why is it necessary ? Pulse will only reach 1 wait handle and I know that AutoREsetEvent is letting only one blocked item to go through and automatically close the gate.

so why writing _signal = false is necessary ? .

  • 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-06-07T05:14:24+00:00Added an answer on June 7, 2026 at 5:14 am

    If the _signal variable stays true, then if another thread calls WaitOne after the Set call, it wouldn’t wait. You don’t just have to consider how existing waiting threads are handled – you have to consider the overall state of the object.

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

Sidebar

Related Questions

Is there an equivalent of Monitor.Pulse and Monitor.Wait that I can use in conjunction
I can use object.wait , object.notify and synchronized blocks to solve the producer consumer
A thread can use Object.wait() to block until another thread calls notify() or notifyAll()
is there any javascript code wrap that can be use to wait for Jquery
I can use the PRINT statement in a stored procedure to debug my code.
You can use the URL helper in Code Igniter to load CSS and Javascript
Is there a standard Loading, please wait dialog I can use in Android development,
Im new to WCF and what i know till now that i can use
I can use FireFox and FireBug, in a pane, I can open a .css
I can use stat() to figure out what permissions the owner, group, or others

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.