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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:39:15+00:00 2026-05-28T03:39:15+00:00

This is admittedly an unusual question; I would never recommend replacing a boolean with

  • 0

This is admittedly an unusual question; I would never recommend replacing a boolean with a ManualResetEvent in typical .NET development. In this case, I already need a ManualResetEvent to indicate connection status to another thread; given that, it occurs to me that the use of a boolean with the same semantic meaning is redundant.

OK, specifics: I have a worker thread that should process messages when the following conditions are true:

  • “Client” connected
  • “Recipient” connected

The “client” and “recipient” connections are TCP sockets which other threads are monitoring; when either connection status changes, the corresponding WaitHandle will be set (Connected) or reset (Disconnected).

Originally, I had a boolean indicated the connection state (for UI). Now that I am using WaitHandles to signal the worker thread, it seems advantageous to eliminate the boolean state variables entirely and just use the WaitHandles.

waitEvent.WaitOne( 0 )

returns the state of the handle without blocking, making it functionally identical to testing a boolean value (with the added advantage of thread-safe operation).

So, given that I am already going to be using the WaitHandles, and I don’t like the idea of maintaining the state (same semantic meaning) into two different variables, is there any reason why I can’t just use the WaitHandles? The most significant counter-argument I can think of is runtime performance: time to test a boolean vs. time to test the WaitHandle; but I don’t think performance will be that significantly affected.

Am I missing anything significant here?

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-28T03:39:15+00:00Added an answer on May 28, 2026 at 3:39 am

    The benefit of just using the ManualResetEvent are that you only have one variable tracking the same state. However, as you mentioned, there will be overhead to read the state back out.

    You have to ask if that overhead is significant enough to justify tracking the same state in two places and risk them becoming out-of-sync.

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

Sidebar

Related Questions

This is admittedly a rather loose question. My current understanding of singletons is that
This is an admittedly silly question, but I honestly don't know if this is
Okay, Now admittedly this sounds like a silly question; But, I actually have a
This is a admittedly a bit of a terrible question, but my search results
I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
Compared to most people on this site I am admittedly a novice. I wanted
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw
I've got an IQueryable repository (admittedly this is the first time I've tried this)
Admittedly, this is a strange problem for me to have, but here is what

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.