Null object that is not null

Posted by Guillaume on Stack Overflow See other posts from Stack Overflow or by Guillaume
Published on 2010-05-10T09:15:58Z Indexed on 2010/05/10 9:24 UTC
Read the original article Hit count: 423

Filed under:
|
|
|

Hello,

I use 2 threads to act like a produce/consumer using double queue (http://www.codeproject.com/KB/threads/DoubleQueue.aspx). Sometimes in my 2nd thread, I get an object that is NULL but it should not be as I filled it in the first thread.

I tried this:

if(myObject.Data == null)
{
  Console.WriteLine("Null Object") // <-- Breakpoint here
}

When I my break point hits, I can watch myObject.Data and indeed it's NULL, but when I hit F10 and then go to the next line (which is } ) myObject.Data is not NULL. I also added a lock on myObject before

if ....

to be sure that no one whould use this object.

How is that possible and what can I do ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about thread