private void DealOpcReWritDate()
        {
            try
            {
                while (true)
                {
                    lock (OpcReWriteQueue)
                    {
                        while (OpcReWriteQueue.Count > 0)
                        {
                            try
                            {
                                OpcReWrite q = OpcReWriteQueue.Peek();
                                DicOpcSer[q.OpcServerName].WriteByType(q.groupID + q.itemType, (int)q.value, q.itemIndex);
                                OpcReWriteQueue.Dequeue();
                            }
                            catch (Exception ex)
                            {
                                throw new Exception(ex.Message);
                            }
                        }
                    }
                    Thread.Sleep(1000);
                }
 
            }
            catch (Exception ex)
            {
                LOG.Error(ex.Message);
            }
  
        }
当DicOpcSer[q.OpcServerName].WriteByType(q.groupID + q.itemType, (int)q.value, q.itemIndex);出错时线程不再执行。不知道什么原因。线程

解决方案 »

  1.   

    是不是抛出异常了,抛出异常之后如果没有抓异常,线程就会结束,你可以把断点设置在 throw new Exception(ex.Message);这句上,
      

  2.   

    很清楚啊。内层异常处理中,未做处理,又抛出异常。这样,外层try就捕获到了内层抛出的异常,外层catch中写完日志后,就退出了线程函数,线程自然结束了。
      

  3.   

    如果你想出错后还继续运行线程,应该在内层catch中写日志,不要抛异常。如果认为这个错误很严重,线程不能继续执行,应去掉内层的try……catch