得到“对象引用未设置为对象的实例。”在服务器上部署时出错,但在本地运行/调试它很好[重复]

时间:2021-03-21 16:54:57

This question already has an answer here:

这个问题在这里已有答案:

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.

我与另一个线程有同样的错误。这让我觉得我的主题有一些问题。但是,正如我所说,当我在本地调试/运行时,它可以正常工作而不会出错。请帮忙。提前致谢。

1 个解决方案

#1


There is a timing issue here:

这里有一个时间问题:

   mProcessingValidStatesChangeThread.Start();
}

mProcessingValidStatesChangeSignal = new AutoResetEvent(false);

Because the starting code directly accesses mProcessingValidStatesChangeSignal

因为起始代码直接访问mProcessingValidStatesChangeSignal

#1


There is a timing issue here:

这里有一个时间问题:

   mProcessingValidStatesChangeThread.Start();
}

mProcessingValidStatesChangeSignal = new AutoResetEvent(false);

Because the starting code directly accesses mProcessingValidStatesChangeSignal

因为起始代码直接访问mProcessingValidStatesChangeSignal