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

  • Home
  • SEARCH
  • 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 108587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:56:07+00:00 2026-05-11T01:56:07+00:00

I have a system-wide manual reset event that I create by doing the following:

  • 0

I have a system-wide manual reset event that I create by doing the following:

EventWaitHandle notifyEvent = new EventWaitHandle(false, EventResetMode.ManualReset, notifyEventName, out createdEvent); 

Several processes create this event (e.g. it is shared amongst them). It is used for notifying when something gets updated.

I’d like to be able to set this event so that all of processes waiting on it are signaled and then immediately reset it so that subsequent Waits on the event are blocked.

If I do a

notifyEvent.Set(); notifyEvent.Reset(); 

It will sometimes notify all listening processes.

If I do a

notifyEvent.Set(); Thread.Sleep(0); notifyEvent.Reset(); 

More processes get notified (I assumed this would happen since the scheduler has a chance to run).

And if I do

notifyEvent.Set(); Thread.Sleep(100); notifyEvent.Reset(); 

Then everything seems to work out fine and all processes (e.g. ~8) get notified consistently. I don’t like the use of a ‘magic number’ for the Sleep call.

Is there a better way to notify all listeners of an OS event in other processes that an event has occurred so that everyone listening to it at the time of notification receive the event signal and then immediately reset the event so that anyone else that goes to listen to the event will block?

UPDATE: A Semaphore doesn’t seem to be a good fit here since the number of listeners to the event can vary over time. It is not known in advance how many listeners there will be when an even needs to be notified.

  • 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. 2026-05-11T01:56:08+00:00Added an answer on May 11, 2026 at 1:56 am

    You’re using the EventWaitHandle class incorrectly. A reset event shouldn’t be used to signal multiple threads. Instead, you need to create a reset event for each thread and then when you’re ready loop through them all and use Set(). The master thread should not be calling the Reset() method. Each thread should be responsible for closing the gate behind them so to speak.

    Here’s a basic example:

    static class Program {     static void Main()     {         List<ThreadState> states = new List<ThreadState>();         ThreadState myState;         Thread myThread;         string data = '';          for (int i = 0; i < 4; i++)         {             myThread = new Thread(Work);             myState = new ThreadState();             myState.gate = new EventWaitHandle(false, EventResetMode.ManualReset);             myState.running = true;             myState.index = i + 1;             states.Add(myState);             myThread.Start(myState);         }          Console.WriteLine('Enter q to quit.');          while (data != 'q')         {             data = Console.ReadLine();             if (data != 'q')                 foreach (ThreadState state in states)                     state.gate.Set();         }          foreach (ThreadState state in states)         {             state.running = false;             state.gate.Set();         }          Console.WriteLine('Press any key to quit.');         Console.ReadKey();     }      static void Work(Object param)     {         ThreadState state = (ThreadState)param;         while (state.running)         {             Console.WriteLine('Thread #' + state.index + ' waiting...');             state.gate.WaitOne();             Console.WriteLine('Thread #' + state.index + ' gate opened.');             state.gate.Reset();             Console.WriteLine('Thread #' + state.index + ' gate closed.');         }         Console.WriteLine('Thread #' + state.index + ' terminating.');     }      private class ThreadState     {         public int index;         public EventWaitHandle gate;         public bool running;     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a Linux system wide C++ program /usr/bin/PROG_X that uses a configuration
I have a system that combines the best and worst of Java and PHP.
I have a system that uses a meta refresh to a logout page, which
We have a system where customers, mainly European enter texts (in UTF-8) that has
I have two system calls GetSystemTime() and GetThreadTimes() that I need to calculate the
I have a system that creates an order and that order can be billed
I have few variables which are used system-wide in my rails app. It runs
I'm building an application which needs to filter some mouse clicks system-wide. That is,
I have a new web app that is packaged as a WAR as part
I have a system wide installation of RVM on a server. I'm shooting in

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.