1

I have a piece of code when I debug/run locally, it works fine. However, when I deploy it on server, I got the following error.

Message: Object reference not set to an instance of an object.
   at Svcs.Provider.Hosted.AgentState.RemoteIntegration.GenesysAgentState.GenesysDataMockup.ProcessChange()
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

According to the error, the relative code is

        public static void StartThreadProcessing()
        {
            if ((null == mProcessingThread) || (false == mProcessingThread.IsAlive))
            {
                mThreadStop = false;
                mProcessingThread = new Thread(new ThreadStart(ProcessChange));
                mProcessingThread.Start();
            }

            mProcessingSignal = new AutoResetEvent(false);
        }

        public static void ProcessChange()
        {
            try
            {
                while (false == mProcessingSignal.WaitOne(freq) && false == mThreadStop)
                {
                    List<ChangeOV> listChange = ChangeValidStatus();
                    if (listChange.Count != 0)
                        ServiceInterface.GetInstance().ProcessUpdate(listChange);
                }
            }
            catch (Exception ex)
            {
                ..... //Log the ex.message;
            }   
        }

I do have the same error with another thread. That makes me think my thread has some issue. However, as I said, when I debug/run on local, it works fine without error. Please help. Thanks in advance.

Laodao
  • 1,547
  • 3
  • 17
  • 39
  • 2
    Related: [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül May 08 '15 at 14:47
  • this sounds like an `Instance vs Static` Issue.. can you tell us what line the error is happening on.. also why is your logical checks / comparison seem to be backwards `if ((null == mProcessingValidStatesChangeThread)` use the debugger pinpoint where you think this could be happening .. I suspect it's in this line `mProcessingValidStatesChangeThread = new Thread(new ThreadStart(ProcessChangeValidStatus));` – MethodMan May 08 '15 at 14:49
  • 1
    I bet that `AgentStateRemoteServiceInterface.GetInstance()` returns null. – Edgar Hernandez May 08 '15 at 14:51
  • 1
    Another place it might be happening - you might find that in the different environments that the thread is starting up and getting to `while (!mProcessingValidStatesChangeSignal...` before the other thread has hit `mProcessingValidStatesChangeSignal = new AutoResetEvent(false);` – James Thorpe May 08 '15 at 14:51

1 Answers1

0

There is a timing issue here:

   mProcessingValidStatesChangeThread.Start();
}

mProcessingValidStatesChangeSignal = new AutoResetEvent(false);

Because the starting code directly accesses mProcessingValidStatesChangeSignal

H H
  • 263,252
  • 30
  • 330
  • 514