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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:21:12+00:00 2026-05-23T05:21:12+00:00

I have a problem concerning the System.Threading Microsoft .NET namespace. In this namespace, many

  • 0

I have a problem concerning the System.Threading Microsoft .NET namespace. In this namespace, many classes are defined in order to help me managing with threads.
Well, I have a problem, but I do not know what to use, MSDN is vague and I still haven’t got a clue of what classes do what. in particular, my problem concerns synchronization.

The problem

I have a certain number of threads (consider N threads).
At a certain point a thread must stop and wait for at least one of the other thread to do something.
Once one of the N – 1 threads has done a certain task, this thread notifies and the stopped thread will be able to proceed.

So it is just a synchronization issue: a thread must wait to be signalled, that’s all.

Many classes

In System.Threading there are many classes provided in order to handle synchronization issues. There are WaitHandle(s), there are AutoResetEvent(s), there are ManualResetEvent(s) and so on…

Which one whould I use?

The question

My question is: can anybody summarize me which class I should use in order to solve my problem? Could you please tell the most important differences between these classes, or other classes?

The point is that I havn’t really understood what class is responsible of in the synchronization matter: what is the difference, for example, between a WaitHandle and an AutoResetEvent or ManualResetEvent?

What about lock?

In order to handle many threading issue, .net provides lock functionalities and the Monitor class. Is this couple good for my needs?

Thankyou

  • 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-23T05:21:13+00:00Added an answer on May 23, 2026 at 5:21 am

    Albahari’s book is amazing, you should really read through it some time. Its grown alot lately!

    What you want

    You want an EventWaitHandle (EWH), they are nice because there is nothing to pass around, they are used for signaling threads (either in the same or in a different process) and as the name implies, they can be waited on.

    How you use it

    You would open one on the thread that is doing the waiting, you open it with a given name that the other thread is going to know about. Then you wait on that wait handle.

    The signaling thread will open an existing wait handle of the same name (name is a string) and call set on it.

    Differences

    AutoResetEvents and ManualResetEvents both inherit from EWH and they are really just EWH’s, they just act differently. Which one you want just depends on if you want the EWH to act as a gate or a turnstyle. You only care about this if you are using the wait handle more than once or you are waiting on that wait handle by more than one thread. I’ve used wait handles a decent amount (I suppose) and I don’t think I’ve ever used a Manual.

    Important to know

    • Whatever you do, dont pass an instance of a wait handle around, they are meant to be opened seperately by their own threads. The name you specify will ensure that they are the “same” wait handle.

    • If the threads are in different processes, then you will HAVE to prefix the name of the EWH with @"Global\", otherwise the names of the wait handles will be encapsulated within the same process. Alternatively, if you are using them all within the same process, dont use the global namespace. When you don’t specify a prefix with a backslash, one is automatically added to keep it private, but you don’t need to know that prefix.

    • Keep in mind that EWH’s can be permissioned, and if you run into issues with that I reccomend that you use EventWaitHandleRights.FullControl, but you can browse the full EventWaitHandleRights enumeration here.

    • I like to name my EWH’s with a Guid.NewGuid().ToString("N") (Guid.NewGuid & Guid.ToString). I typically do this when the signaling thread is created, since you can easily pass information to it at that time. So in that case, the initial thread creates the string and passes it to the signaling thread when its created. That way both threads know of the name, without having to do any fancy cross-thread passing of variables.

    • EWH implements IDisposable so wrap it in a using block

    Race conditions

    EWH’s are nice because if for whatever reason the signaling thread opens and signals the wait handle before the waiting thread even creates it, everything will still work and the waiting thread will be signaled the instant it hits the wait.

    Because of this, though, the thread that is waiting on it will need to have some error trapping because you will need to call OpenExisting. If you call one of the ctor‘s and the EWH is already opened, you’ll get a UnauthorizedAccessException or a WaitHandleCannotBeOpenedException thrown as described here, under Exceptions. You’ll still be able to open that EWH and get the functionality you need, you may just have to open it instead of create it.

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

Sidebar

Related Questions

I have problem concerning python packages and testing. I'm writing an application using wx
I am using LaTeX and I have a problem concerning string manipulation. I want
I have quite a problem concerning the use of relational database concepts in Delphi
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have Qt Embedded 4.7.4 working on an ARM system, in order to display
I have a problem converting a timestamp in javascript. I have this timestamp: 2011-10-26T12:00:00-04:00
I have been using the following code for months (without problem) in a .NET
I have a problem converting a string binary to a decimal I was using
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime

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.