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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:44:10+00:00 2026-05-13T09:44:10+00:00

I have a strange bug in a multithreaded app: public class MyClass { private

  • 0

I have a strange bug in a multithreaded app:

public class MyClass
{
   private readonly Hashtable HashPrefs;
   public MyClass(int id)
  {
     HashPrefs = new Hashtable();
  } 

  public void SomeMethodCalledFromAnotherThread(string hashKey,string hashValue)
 {
    if (HashPrefs.Contains(hashKey))  // <-- throws NullReferenceException
    {

    }
 }
}

One thread does the :

 SomeQueue.Add(new MyClass(1));

And another thread does the :

 SomeQueue.Dequeue().SomeMethodCalledFromAnotherThread(SomeClass.SomeMethod(),"const value"); 

But how can the second thread call the method before the constructor is finished?

Edit: I added the part with the function parameters, as it seems this might be relevant.
As far as I can tell, the hashKey being passed on cannot be null, as SomeMethod() always returns a relevant string.

As others have pointed out,if the problem was a null haskKey parameter passed to the Contains() , the exception would be ArgumentNullException.

  • 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-13T09:44:10+00:00Added an answer on May 13, 2026 at 9:44 am

    Reflection is one way to do this (SetField).

    A second way to get this curiosity is if you give away the reference too early, by passing this (or sometihng involving an implicit this, such as a field captured into an anonymous method / lambda) out of the .ctor:

    public MyClass(int id)
    {
        Program.Test(this); // oopsie ;-p
        HashPrefs = new Hashtable();
    }
    

    Or more likely (given the question):

    SomeQueue.Add(this);
    

    Another relevant question might be – can it not be assigned in the first place? And the answer to that is yes, especially if you are using serialization. Contrary to popular belief, you can actually bypass the constructors, if you have a reason; DataContractSerializer is a good example of something that does this…

    The following will create a MyClass with a null field:

    MyClass obj = (MyClass)
        System.Runtime.Serialization.FormatterServices.GetUninitializedObject(
            typeof(MyClass));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 348k
  • Answers 348k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Generically speaking (that is, without knowledge of Joomla internals): If… May 14, 2026 at 6:33 am
  • Editorial Team
    Editorial Team added an answer If you are building an FBML application, then yes, your… May 14, 2026 at 6:33 am
  • Editorial Team
    Editorial Team added an answer Yes, you will need at least the Developer Edition (Express… May 14, 2026 at 6:33 am

Related Questions

I have a bug somewhere that is causing my app to just vanish without
I have a really strange enum bug in Java. for(Answer ans : assessmentResult.getAnswersAsList()) {
I have a strange bug in the Visual Studio text editor. All my blank
I have a strange bug in resharper 4.5 in VS 2005. Instead of doing
I'm having a very strange bug in Flex Builder where none of the changes

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.