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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:14:42+00:00 2026-06-09T11:14:42+00:00

Supposed there is something like Hashtable created by Hashtable.Synchronized() which is accessed by multiple

  • 0

Supposed there is something like Hashtable created by Hashtable.Synchronized() which is accessed by multiple thread. and the key value pair is Guid and Object in Hashtable .
One of thread need to polling this Hashtable until a specific Guid key had been added into this list by another thread.

Below is my code .

        public Hashtable syncHt = new Hashtable();
        public void Init()
        {
            Hashtable ht = new Hashtable();
            syncHt = Hashtable.Synchronized(ht);
        }

In the application initialization i will call the init();

And In one of thread I will call isExist to find the specific Guid which is added by some other thread .

public bool isExist(Guid sId)
    {
        while (true)
        {
            if (syncHt.ContainsKey(sId))
            {
                return true;
            }
        }

}

I was wondering whether this loop could be ended. How can I know the Hashtable changed during the polling ?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-06-09T11:14:44+00:00Added an answer on June 9, 2026 at 11:14 am

    Reading and more important assigning to a reference is always atomic in .NET.

    To do atomic operation, use the System.Threading.Interlocked class. See MSDN


    I was wondering whether this loop could be ended.

    It will end when another (only 1 writer allowed) thread inserts the wanted value, yes.

    On MSDN: Hashtable is thread safe for use by multiple reader threads and a single writing thread.

    But your solution is very inefficient. The busy-loop can consume a lot of CPU time for nothing. Storing (boxed) Guids in an old style collection isn’t perfect either.

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

Sidebar

Related Questions

Let's say I load a value from a database which return something like: <?php
Is there a simple way to style element like this? Supposed to be used
I need to implement the following: There is a table A which is supposed
Is there a way to accomplish something like this? I work in Python, but
Is there some way I can do something like: @implementation MyView - (void)drawRect:(CGRect)rect {
Is there a way for JSF to output something like this: <button type=submit ...></button>
There is supposed to be a comma between these two strings foo = ['dumb'
I have a script that is supposed to sit there, happily running in a
There is a following function that is supposed to make a comparison between 2
Is there some agreed upon algorithm of what is supposed to happen when, 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.