Within a C# instance method, can 'this' ever be null?

前端 未结 6 770
栀梦
栀梦 2020-12-17 08:30

I have a situation where very rarely a Queue of Objects is dequeuing a null. The only call to Enqueue is within the class itself:

m_DeltaQueue.Enqueue(this);         


        
6条回答
  •  既然无缘
    2020-12-17 08:41

    Queues are not inherently thread safe. This is your issue. Use a mutex/lock/whatever or look for a thread safe-queue.

提交回复
热议问题