Exemplo n.º 1
0
        public ParseThread(ParseThreadEnv tmpEnv)
        {
            timer.Elapsed  += new System.Timers.ElapsedEventHandler(UpdateAscan);
            timer.AutoReset = true;

            init         = tmpEnv.init;
            clean        = tmpEnv.clean;
            status       = tmpEnv.status;
            inputQueue   = tmpEnv.captureOutQueue;
            ascanQueue   = tmpEnv.ascanQueue;
            mergeInQueue = tmpEnv.mergeInQueue;

            mergeInQueueElement = new MergeInQueueElement();
            ascanQueueElement   = new AscanQueueElement();
            boardStatusPacket   = new BoardStatusSetPacket();

            thread = new Thread(parseFunc);
            thread.IsBackground = true;

            updateCallBack = new updateDelegate(FormList.MDIChild.updateAscanbytimer);
        }
Exemplo n.º 2
0
        private void mergeFunc()
        {
            int dequeueResult;
            //bool isError;
            bool stop;
            bool isParseSuccess;
            int  endCount;
            MergeInQueueElement outqueueElement;
            QueueData           endQueue;

            //isError = false;
            stop            = false;
            isParseSuccess  = false;
            endCount        = 0;
            outqueueElement = new MergeInQueueElement();
            endQueue        = new QueueData();
            endQueue.isEnd  = true;  //A queue atom represent the end of the input.

            init.handclasp_meet();

            while ((!GlobalQuit.Quit) && (!stop))
            {
                try
                {
                    for (int i = 0; i < mergeInList.Count; i++)
                    {
                        dequeueResult = mergeInList[i].DequeueWithSemaphor(ref outqueueElement, ConstParameter.TimeOutMilliSecondValue);

                        if (dequeueResult == -1)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog("MergeThread timed out when semaphor wait for receiving!", st);
#if USE_WARNING
                            MessageBox.Show("融合线程信号量超时,请马上设置断点检查。位置:MergeThread.mergeFunc");
#endif
                            status = ThreadCondition.error;
                            //isError = true;
                        }
                        else if (dequeueResult == 0)
                        {
                            continue;
                        }
                        else if (dequeueResult == 1)
                        {
                            //if receive the end atom of queue, just break and stop the thread.
                            if (outqueueElement.IsEnd == true)
                            {
                                endCount++;
                                if (endCount == mergeInList.Count)
                                {
                                    endCount = 0;
                                    stop     = true;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            isParseSuccess = parsePacket(outqueueElement.setPacket, i);
                            if (!isParseSuccess)
                            {
                                StackTrace st = new StackTrace(new StackFrame(true));
                                LogHelper.WriteLog("The format of packet is wrong or MergeThread timed out when Enqueue!", st);
#if USE_WARNING
                                MessageBox.Show("融合线程获取的数据格式错误或入队失败,请马上设置断点检查。位置:MergeThread.mergeFunc");
#endif
                                status = ThreadCondition.error;
                                //isError = true;
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    StackTrace st = new StackTrace(new StackFrame(true));
                    LogHelper.WriteLog(e, st);
#if USE_WARNING
                    MessageBox.Show("检测到异常,请马上设置断点检查。位置:MergeThread.mergeFunc");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }
            init.handclasp_force();

            measureQueueElement.IsEnd = true;
            measureQueue.Enqueue(measureQueueElement);

            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }
Exemplo n.º 3
0
        /**Parse thread function.*/
        private void parseFunc()
        {
            //DEFINATION
            bool isDequeSuccess;
            bool isParseSuccess;
            //bool isError;
            CaptureOutQueueElement outqueueElement;
            //A queue atom represent the end of the ascan queue.
            AscanQueueElement ascanEndElement;
            //A queue atom represent the end of the mergein queue.
            MergeInQueueElement mergeInEndElement;

            //INIT
            isDequeSuccess = false;
            isParseSuccess = false;
            //isError = false;
            outqueueElement         = new CaptureOutQueueElement();
            ascanEndElement         = new AscanQueueElement();
            ascanEndElement.IsEnd   = true;
            mergeInEndElement       = new MergeInQueueElement();
            mergeInEndElement.IsEnd = true;

            //PROCESSING
            init.handclasp_meet();

            while (!GlobalQuit.Quit)
            {
                try
                {
                    isDequeSuccess = inputQueue.Dequeue(ref outqueueElement);

                    if (isDequeSuccess)
                    {
                        //if receive the end atom of queue, just break and stop the thread.
                        if (outqueueElement.IsEnd == true)
                        {
                            break;
                        }
                        // LogFile.write("开始分发");
                        isParseSuccess = parsePacket(outqueueElement.setPacket);
                        //  LogFile.write("分发结束");
                        if (!isParseSuccess)
                        {
                            StackTrace st = new StackTrace(new StackFrame(true));
                            LogHelper.WriteLog("The format of packet is wrong or ParseThread timed out when Enqueue!", st);
#if USE_WARNING
                            MessageBox.Show("分发线程获取的数据格式错误或入队失败,请马上设置断点检查。位置:ParseThread.parseFunc");
#endif
                            status = ThreadCondition.error;
                            //isError = true;
                        }
                    }
                    else
                    {
                        StackTrace st = new StackTrace(new StackFrame(true));
                        LogHelper.WriteLog("ParseThread timed out when Dequeue!", st);
#if USE_WARNING
                        MessageBox.Show("分发线程出队超时,请马上设置断点检查。位置:ParseThread.parseFunc");
#endif
                        status = ThreadCondition.error;
                        // isError = true;
                    }
                }
                catch (Exception e)
                {
                    StackTrace st = new StackTrace(new StackFrame(true));
                    LogHelper.WriteLog(e, st);
#if USE_WARNING
                    MessageBox.Show("检测到异常,请马上设置断点检查。位置:ParseThread.parseFunc");
#endif
                    status = ThreadCondition.error;
                    //isError = true;
                }
            }

            init.handclasp_force();

            //ascanQueue.EnqueueWithSemaphor(ascanEndElement);
            //mergeInQueue.EnqueueWithSemaphor(mergeInEndElement);

            clean.handclasp_meet();

            status = ThreadCondition.exit;
        }